Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

h1 tag class (alternate)

Tags:

html

css

seo

I know that h1 tag is important for SEO, so all my title is H1 (bravo!)

Now, I need to have a title (as the first line of a text ) a little different on some pages.

Usually, I just duplicate h1 as h2 and alternate.

The question: Is it possible to add a class to the title tag... (I have try without success)

like image 547
menardmam Avatar asked Nov 12 '09 21:11

menardmam


People also ask

What can I use instead of h1b?

H2 heading tag An H2 tag marks the first sub-heading after your document's main heading. It defines the second-level headings on your webpage. Like an H1 tag, an H2 tag also appears larger than the rest of your main body text.

Can h1 tag have class?

The class attribute assigns one or more classnames to the <h1> to <h6> tags. Classnames are defined in a stylesheet or in a local <style> element. Classes, i.e. classnames, are used to style elements.

Can the element h1 be replaced with h1?

It's fine to refer to the <h1> element as the h1 heading .

Is title and h1 the same?

What's the Difference? In HTML terms, a Title Tag is expressed as "title" and the H1 Tag is expressed as "h1". Both serve as titles to describe what your webpage is about. Because both the Title Tag and the H1 Tag share the same broader purpose, it is easy to understand why people confuse them.


4 Answers

You can style a header like this:

h1 { color: red; }

Or like this:

<h1 class="fancy">Fancy</h1>

.fancy { font-family: fantasy; }

If it's not working:

  • Check you don't have an old stylesheet cached (ctrl-F5 to reload)
  • Check you don't have any rules overriding your class (inspecting with Firebug or similar is very helpful here).
  • Check for typos in the HTML and CSS

Edit:

It sounds like you had h1 .myClass instead of h1.myClass - there's an important distinction:

h1 .myClass { } /* any element with class="myClass" within an <h1> */
h1.myClass  { } /* any <h1> with class="myClass" */
like image 93
Greg Avatar answered Nov 15 '22 23:11

Greg


Sure you can:

<h1 class="someclass">…</h1>

The class attribute is a in the attribute group coreattrs of core attributes that can be used with the h1 element.

like image 29
Gumbo Avatar answered Nov 15 '22 22:11

Gumbo


It sounds like you are using h1 for all titles on the page. Typically you would have a single h1 tag on the page for what the page contains (with text at least partly matching the title of the page), and lesser header tags for headlines of different parts of the content. That way you give most information to the search engines about what's important on the page. There are of course pages that doesn't fit into this model, but many do.

There are many different ways that you can specify a style for headers. For example:

For all h1 tags:

h1 { font-weight: bold; }

For all h1 and h2 tags:

h1, h2 { margin: 10px; }

For all h1 tags inside an element with id="main":

#main h1 { background: #ccc; }

For all h2 tags with class="Info":

h2.Info { color: #000; }

For all h3 tags inside an element with class="More":

.More h3 { text-decoration: underline; }
like image 20
Guffa Avatar answered Nov 15 '22 23:11

Guffa


You can add a class to an <h1> tag. Like this:

<h1 class="myclass"> ... </h1>

You can easily style it like this:

<style type="text/css">
.myclass { color : green }
</style>
like image 35
Asaph Avatar answered Nov 15 '22 22:11

Asaph