Refactor: extract HTML attribute handling.