Join Morten Rand-Hendriksen for an in-depth discussion in this video The dual purpose of web code, part of Web Programming Foundations.
- When writing for the web, you're writing for two audiences, the human being accessing the content and the technology used to access that content, in most cases a web browser. The key to writing accessible, understandable, and usable content is to write content for people and then mark it up so it can also be parsed properly by computers. Humans are, for the most part, pretty decent communicators. And when we write content, the structuring of that content comes almost naturally given the proper training.
Start with a heading, then write a paragraph and another paragraph, and add an image with a caption and maybe another paragraph followed by a subheading, and so on. The challenge comes when we have to explicitly state what each of these things are so they can be marked up and declaratively codified for computers. The goal is to write code that satisfies our end goal, conveying the contents to the persons accessing it in the best way possible. To do so, we have to identify the nature, properties, purpose, and relationships of each element of content so they can be marked up as such.
The first heading is the main heading, so it should have heading level one. The first paragraph is the intro paragraph and should signal this in some way for a viewer without changing the markup. We can do that by adding a drop-cap through CSS. The image has a caption so it should be wrapped in a figure element and the caption as a figcaption element. The next heading is a subheading and should, therefore, have heading level two, and so on. To reiterate, you have two goals, communicate with a human consumer and communicate with a machine.
To do this, you must effectively write the content, identify the nature, property, purpose, and relationships of each element of that content and mark everything up accordingly.
- From URL to website
- Structure of a web document
- Dual-purpose code
- Browsers and editors