`
and ``
* Tags are nestable
* Some tags have key-value attributes
Example:
```html
Header 1
Header 3
A paragraph with some emphasized text.
```
---
# HTML Document
HTML documents single root-element _should_ be the `` tag. It's forest of
children are referred to as the _Document Object Model_ or __DOM__.
Technically there should be only two children of an `` tag:
``: Encapsulates meta-data about the page including its title, and
references to external resources (CSS, JavaScript)
``: Encapsulates everything to be displayed on the page
__Note__: With HTML5 (and many browsers' parsers for other variations of HTML)
these first-level tags can be omitted as they can be inferred based on the tag
being parsed.
---
# HTML5 Bootstrap Example
```html
Bootstrap 101 Template
Hello, world!
```
---
# Common HTML Tags
Different HTML tags should be used for different elements on the page. There
exist a handful of formatting and style tags, however, those should be avoided
in-favor of using CSS (cascading style sheets) -- we will discuss CSS later.
* __h1__ through __h6__: various header-level tags (h1 should be page title)
* __p__: paragraph text
* __ul__, __ol__: unordered and ordered list wrapper
* __li__: list item (nested within ul, or ol)
* __table__: begin a table
* __tr__: begin a table row within a table
* __td__: one entry in a table row
* __span__: An inline grouping mechanism
* __div__: A block-level grouping mechanism
---
# Anchor Tag
The most innovative part about HTML is the __HyperText__ part provided by the
anchor tag: ``
Using an anchor tag one can link to another document (resource) anywhere on the
web.
```html
CS291A
```
---
# HTML Forms
An HTML form provides a convenient way to collect input from a web browser.
```html
```
## Notes
* `method` defaults to __GET__. Recall that __GET__ requests shouldn't
have side-effects so __POST__ is more-often more appropriate.
* The default encoding is `application/x-www-form-urlencoded`
---
# Attributes `id` and `class`
HTML elements have two ubiquitous tags:
`id`: A unique identifier that makes it easy to find one element in the DOM
`class`: Multiple classes can be assigned to DOM elements, and the same class
can be applied to multiple DOM elements (many-to-many relationship).
```html
Error.
```
DOM IDs and classes are very useful for applying CSS, and adding JavaScript
callback hooks to elements on the page.
---
# Introduction to Cascading Style Sheets (CSS)
---
# The `
Hello World
```
---
# Style via ID
DOM elements can be styled multiple ways.
Here we are styling all DOM elements with ID `header` (there should be at most
one per page).
IDs are prefixed with the `#` symbol in CSS.
```html
```
---
# Style via Class
Here we are styling all DOM elements with class `alert`.
Classes are prefixed with the `.` symbol in CSS.
```html
Hello World
```
---
# Inline Styles
We can use the `style` attribute on HTML tags to directly style
DOM elements.
```html
Hello World
```
---
# Contradictory Styles
```html
Hello World
```
> What color is Hello World?
---
# Simplified Rule Precedence
In general more specific rules have higher precedence than less specific rules.
Precedence order (highest first):
* `!important` rules (e.g., `span {color: blue !important};`)
* Inline style
* ID
* Class
* HTML Tag
It gets more complicated, but understanding these rules will go a long way.
---
# External Style Sheets
Style definitions are most often provided through separate CSS files, rather
than `