Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Can I use a heading element inside a label element?

Is it ok to put other elements like <h1> <h2> <b> inside <label> elements, or it is better to use style?

<label for="B"><b>like this</b></label>
<label for="h1"><h1>like this</h1></label>

it is working, but is it a good coding

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Per MDN, font-weight styles should be used over <b> (in general, not just in labels)

However, you should not use <b> for styling text or granting importance. If you wish to create boldface text, you should use the CSS font-weight property. If you wish to indicate an element is of special importance, you should use the <strong> element.

As for headings, they are block level elements so should not be inside a label (which is an inline element). In general, headings should not be used to just change the font size of an element (source).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading