Web Design with HTML and CSS

(National Geographic (Little) Kids) #1

58


Web languages

Web Design with HTML and CSS Digital Classroom

The details of XHTML syntax


There is little fundamental diff erence between HTML 4.0 and XHTML 1.0 — the two
standards previously released by the W3C (World Wide Web Consortium). As XHTML was
defi ned, it was created so that pages written in XHTML also work in browsers that render
current HTML. The tags and attributes of XHTML and HTML remained the same, but the
syntax of XHTML code is more strict.The most signifi cant diff erences between XHTML
and HTML are as follows:


  • In XHTML, all tags must be lowercase.

  • XHTML requires all tags to be closed — meaning that there must be a tag at the start
    and end of the element being tagged — such as a headline, paragraph, or image.


All tags in XHTML must close, even special tags that technically don’t require an open and close
tag. For example the <br> tag which creates a line break, uses a special self-closing syntax. A tag
that self-closes looks like this (with a space and a forward slash):
<br />


  • XHTML requires proper nesting of tags. In the following example, the tag to
    emphasize text opens within the

    headline tag. As such, it must be closed before
    the

    is closed.

    Smoothies are great!


    We’ve used XHTML-compliant code throughout this book as we provide HTML5 examples,
    which helps make your designs compatible with modern browsers and mobile devices.


Doctype lets the web browser know what to expect


The start of every web page should include a Doctype declaration, telling the Doctype
declaration tells the web browser a little bit of information about what it is going to see on
the page. Because there are diff erent specifi cations for XHTML and HTML the web browser
knows which language it’s about to see and render. Because a browser renders the page
starting at the top line and then moves down, placing your doctype on the fi rst line makes a
lot of sense. While it’s not required, it’s good form to always use Doctype at the start of your
HTML pages. The doctype for HTML 4.0.1 looks like this:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
When a web browser sees a doctype declaration, the browser expects that everything on the
page that follows will use that language. If the page adheres to the specifi cations perfectly, it is
considered valid.
Free download pdf