Portfolio

Can I add a <span> inside the H1 tag?

Is this the correct method to use the span tag inside the H1 tag?

<h1> <span class="boardit">Portfolio</span> </h1> 

I know that we can write it this way ... and also follow the syntax below on my own website ..

 <h1 class="boardit"> <span>Portfolio</span> </h1> 

However, I just wanted to know a cleaner html form ..

+78
html
Sep 23 '11 at 4:20
source share
8 answers

Yes, you can.

HTML4 has this to say :

 <!ENTITY % heading "H1|H2|H3|H4|H5|H6"> <!-- There are six levels of headings from H1 (the most important) to H6 (the least important). --> <!ELEMENT (%heading;) - - (%inline;)* -- heading --> 

And %inline; :

 <!ENTITY % inline "#PCDATA | %fontstyle; | %phrase; | %special; | %formctrl;"> 

And %special; includes <span> .

HTML5 has this to say :

Allowed Content
Phrase content

And Content Phrasing includes Fragmented elements , which includes a <span> .

+157
Sep 23 '11 at 4:30
source share

Yes, you can. It can be used to format part of the h1 block:

 <h1>Page <span class="highlight">Title</span></h1> 

If the style applies to the whole h1 block, I do this:

 <h1 class="highlight">Page Title</h1> 
+21
Sep 23 '11 at 4:27
source share

Yes, usually use a span inside h1 . span is an inline element, so it can usually use it in everything (which allows elements inside it!)

And there is actually no cleaner way to do this sometimes, say if you want to style only part of h1 .

On the other hand ... do not do this if you do not need it, as it is a little ugly :)

+3
Sep 23 '11 at 4:28
source share

Yes, that's good, but why not

  <h1 class="boardit"> Portfolio </h1> 

If that's all you do?

+2
Sep 23 '11 at 4:28
source share

Yes, you can. The span displays built-in, so it should not affect the H1 style.

+1
Sep 23 '11 at 4:28
source share

Yes, we can use the span tag with header tags, and there is nothing wrong with it. Indeed, it is widely used for heading styles, especially for coloring a specific word or letter.

0
May 20 '13 at 19:14
source share

Yes, we can use the span tag with header tags, and there is nothing wrong with it. Indeed, it is widely used for heading styles, especially for coloring a specific word or letter.

0
May 20 '13 at 19:49
source share
 <h1 style="display:inline;">Bold text goes here</h1> <span style="display:inline;">normal text goes here</span> 

Think of the lines - Work for me - use display: inline prop

-2
Aug 11 '14 at 15:35
source share



All Articles