views:

315

answers:

3

What would be the best method to code heading/title of <ul> or <ol>? Like we have <caption> in <table>. and we don't want to make them bold

Example image:

alt text

This is ok

<p> heading </p>
<ul> 
<li>list item </li>
<li>list item </li>
<li>list item </li>
</ul>

or always headings should be used?

<h/3/4/5/6> heading </h/3/4/5/6>
<ul> 
<li>list item </li>
<li>list item </li>
<li>list item </li>
</ul>
+3  A: 

Always use heading tags for headings. The clue is in the name :)

If you don’t want them to be bold, use CSS, e.g.

HTML:

<h3 class="list-heading">heading</h3>

<ul> 
    <li>list item </li>
    <li>list item </li>
    <li>list item </li>
</ul>

CSS

.list-heading {
    font-weight: normal;
}

In HTML5, you can associate the heading and the list more strongly by using the <section> element. (<section> doesn’t work properly in IE without some JavaScript though.)

<section>
    <h1>heading</h1>

    <ul>
        <li>list item </li>
        <li>list item </li>
        <li>list item </li>
    </ul>
</section>

You could do something similar in HTML 4:

<div class="list-with-heading">
    <h3>Heading</h3>

    <ul>
        <li>list item </li>
        <li>list item </li>
        <li>list item </li>
    </ul>
</div>

Then style thus:

.list-with-heading h3 {
    font-weight: normal;
}
Paul D. Waite
but i'm using <h3> somewhere else in same page in bold style. and how to make relation between list and heading like table and caption
metal-gear-solid
although ur answer looking good but will wait some more suggestion
metal-gear-solid
Sure: that’s what the class is for on the `<h3>`, to give you a hook to style it differently.There’s no way in HTML 4 to actually associate the `<h3>` and the `<ul>`. HTML5 has sectioning elements (`<section>`, `<article>`) that wrap associated content. The nearest in HTML 4 is `<div>`.
Paul D. Waite
@Paul. Since you mention HTML5, do you think that "figure" might be more appropriate than "section"? Then the h3 would become "figcaption".
Alohci
Ooh, hadn’t heard of `<figure>` yet. I’d guess that in the example given in the question, the list is part of the document’s normal flow, and wouldn’t make much sense if removed. Thus it doesn’t sound like the description of what figure is for: “...illustrations, diagrams, photos, code listings, etc, that are referred to from the main content of the document, but that could, without affecting the flow of the document, be moved away from that primary content” (See http://dev.w3.org/html5/spec/Overview.html#the-figure-element). Complete judgment call though.
Paul D. Waite
Hmm, yes. Good answer. Thanks.
Alohci
A: 

how about making the heading a list-element with different styles like so

<ul>
 <li class="heading">heading</li>
 <li>list item</li>
 <li>list item</li>
 <li>list item</li>
 <li>list item</li>
</ul>

and the CSS

ul .heading {font-weight: normal; list-style: none;}

additionally, use a reset CSS to set margins and paddings right on the ul and li. here's a good reset CSS. once you've reset the margins and paddings, you can apply some margin on the list-elements other than the one's with the heading class, to indent them.

pixeltocode
but how screen reader will know first li is heading of all other li
metal-gear-solid
@Jitendra: You could use an "aria-labelledby" attribute on the ul to point to the first li to inform screen readers of the relationship.
Alohci
A: 

h3 is absolutly a better solution than h2, h1 or h6 !

1/ You have to use specific level : if you're in a h1, use h2, if you're in a h5, use h6 (if you're in a h6... hum, use strong or em for exemple). It not a obligation but a question of accessibility (http://tinyurl.com/ylm4oqn, green part).

2/ You don't have to give title to list... because this element it doesn't exist. So screen reader will not use something special.

Therefore, using Hn is probably one of the best solution, but surely not a specific level.

Alysko
My question is not "Which heading level should be used"?
metal-gear-solid
Yup: the `<h3>` in my answer is just an example. In HTML 4, you’d use whatever heading level is appropriate at that point in the document. (Whereas in HTML5, you’d throw a `<section>` around it, stick in an `<h1>`, and get on with your life.)
Paul D. Waite