I keep coming across the use of this word and I never understand its use or the meaning being conveyed.

Phrases like...

"add semantics for those who read"

"HTML5 semantics"

"semantic web"

"semantically correctly way to..."

... confuse me and I'm not just referring to the web. Is the word just another way to say "grammar" or "syntax"?


+2  A: 

Check out this wiki page:

Very good description.

Michael Bazos
+8  A: 

Syntax is structure. Semantics is meaning. Each different context will give a different shade of meaning to the term.

HTML 5, for example, has new tags that are meant to provide meaning to the data that is wrapped in the tags. The <aside> tag conveys that the data contained within is tangentially-related to the information around itself. See, it is meaning, not markup.

Take a look at this list of HTML 5's new semantic tags. Contrast them against the old and more familiar HTML tags like <b>, <em>, <pre>, <h1>. Each one of those will affect the appearance of HTML content as rendered in a browser, but they can't tell us why. They contain no information of meaning.

Adam Crossland

From my view, it's almost like looking at syntax in a grammatical way. I can't speak to semantics in a broad term, but When people talk about semantics on the web, they are normally referring to the idea that if you stripped away all of the css and javascript etc; what was left (the bare bones html) would make sense to be read.

It also takes into account using the correct tags for correct markup. This stems from the old table-based layouts (tables should only be used for tabular data), and using lists to present list-like content.

You wouldn't use an h1 for something that was less important than an h2. That wouldn't make sense.

+1  A: 

It is not just Computer Science terminology, and if you ask,

What is the meaning behind this Computer Science lingo?

then I'm afraid we'll get in a recursive loop just like this.

haha... I wasn't aware of the recursive Google Search. That is hilarious!
@Hristo - hehe, I don't click that link myself anymore. Impossible to get out :P
+4  A: 

It means "meaning", what you've got left when you've already accounted for syntax and grammar. For example, in C++ i++; is defined by the grammar as a valid statement, but says nothing about what it does. "Increment i by one" is semantics.

HTML5 semantics is what a well-formed HTML5 description is supposed to put on the page. "Semantic web" is, generally, a web where links and searches are on meaning, not words. The semantically correct way to do something is how to do it so it means the right thing.

David Thornley
ahh ok. that is simple enough... meaning. thank you
+4  A: 

Semantics are the meaning of various elements in the program (or whatever).

For example, let's look at this code:

int width, numberOfChildren;

Both of these variables are integers. From the compiler's point of view, they are exactly the same. However, judging by the names, one is the width of something, while the other is a count of some other things.

numberOfChildren = width;

Syntactically, this is 100% okay, since you can assign integers to each other. However, semantically, this is totally wrong, since the width and the number of children (probably) don't have any relationship. In this case, we'd say that this is semantically incorrect, even if the compiler permits it.

Mike Caron
Thanks. That makes a lot more sense.
multiChildStroller.width = numberOfChildren
+1  A: 

In the HTML world, "semantic" is used to talk about the meaning of tags, rather than just considering how the output looks. For example, it's common to italicize foreign words, and it's also common to italicize emphasized words. You could simply wrap all foreign or emphasized words in <i>..</i> tags, but that only describes how they look, it doesn't describe why they look that way.

A better tag to use for emphasized word is <em>..</em>, because it conveys the semantics of emphasis. The browser (or your stylesheet) can then render them in italics, and other consumers of the page will know the word is emphasized. For example, a screen-reader could properly read it as an emphasized word.

Ned Batchelder