...

View Full Version : Semantics - What does that mean?



Dodge
02-24-2005, 06:15 PM
Hi all,

I've read several posts here recently that mention having code that is "semantically correct"... then I just read a post that said (I think) that the markup can be valid but not semantically correct...

Okay - I'm confused. ;)

Could someone define "semantically correct" for me - being a bit anal myself I like the idea already. :D

Thanks
Dodge

cfc
02-24-2005, 06:24 PM
I beleive that "semantically correct" refers to elements being used for what they're supposed to be used for.

For example, tables are valid XHTML but their use for layout is not semantically correct as most page layouts aren't exclusively tabular data.

liorean
02-24-2005, 06:27 PM
Semantically correct usage of elements means that you use them for what they are meant to be used for. It means that you use tables for tabular data but not for layout, is means that you use lists for listing things, strong and em for giving text an emphasis, and the like.

You know, when I first read the title of this thread I thought it was a pun...

rmedek
02-24-2005, 10:10 PM
markup can be valid but not semantically correct...

Okay - I'm confused. ;)

Here's an example: a menu contained with a blue box.

Valid, well-formed... not semantically correct:


<div id="blue">
<div id="menu">
<div class="link"><a href="#">link</a></div>
<div class="link"><a href="#">link</a></div>
<div class="link"><a href="#">link</a></div>
</div>
</div>


Actually, it's not really semantically incorrect, either... it's just semantically empty.

Valid, well-formed, semantically correct:


<ul id="menu">
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
<li><a href="#">link</a></li>
</ul>

The CSS will define the ul as being a blue container box. Now we've got some meaning here (an unordered list of links).

A read through the HTML/CSS archives will have some great discussions on various semantics, as it can sometimes boil down to personal opinion (i.e., what describes this better, this or this?)

Dodge
02-24-2005, 10:31 PM
How interesting! Thanks for the expanations.! :)

I will do some reading on this.

Thanks
Dodge

ronaldb66
02-25-2005, 08:19 AM
Maybe it was already said in a sort of roundabout way, but semantics is all about adding meaning.
The purpose of markup is adding meaning to plain text; semantically correct markup is thus adding correct meaning.
If a piece of text is supposed to be a header, correct markup would use a header element.
If a piece of text is supposed to be a paragraph, you mark it up as one.
An unordered list of items? Guess what: ul's and li's.
Andsoon, andsoforth.

Why would you do this? Semantically correct markup provides instant style hooks, default styling for when CSS is not applicable (text browsers, screen readers, etc.), and an indication to SE spiders to assess the relevance of your pages.

duderdude2
02-25-2005, 10:27 PM
Where are these HTML/CSS archives you speak of? =)

rmedek
02-25-2005, 10:37 PM
oh, I meant just looking through some of the previous posts here in the HTML/CSS forum. Some good ones:

http://codingforums.com/showthread.php?t=51046
http://codingforums.com/showthread.php?t=39420
http://codingforums.com/showthread.php?t=39586
http://codingforums.com/showthread.php?t=34638

Really, any thread in the html/css forum will probably involve semantics in some way... if you're into it I'd suggest reading through every question when they pop up just to see if you grasp something new.

Dodge
02-25-2005, 10:41 PM
Really, any thread in the html/css forum will probably involve semantics in some way... if you're into it I'd suggest reading through every question when they pop up just to see if you grasp something new.

Agreed - and that's what I have been doing. I'm trying to play the part of a sponge and soak up as much as I can. ;)

I even read the questions/replies from the forums I'm not directly involved in (JavaScript, ASP, etc...) hoping to retain and use it at a later time.

I very much appreciate the replies to this topic and have been trying to approach my code with semantics in mind.

Thanks
Dodge



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum