HTML¶
What is HTML?¶
- HTML stands for Hypertext Markup Language
- HTML is the standard markup language for creating Web pages
- HTML defines the structure of Web content
- HTML is not a programming language, it is a markup language that uses tags to define elements within a document
- Hypertext is what makes the World Wide Web (WWW) possible
- Hypertext refers to cross-references (links, images, files, etc.) that connect web pages to one another, either within a single website or between websites
- HTML5 is called a living standard as it is constantly evolving.
https://developer.mozilla.org/en-US/docs/Web/HTML
Anatomy of an HTML document¶
DOCTYPE
declaration is an instruction to the web browser about what version of HTML the page is written in.<html>
is the root element of an HTML page.<head>
contains the page metadata.<meta charset="utf-8">
sets the character encoding for the page.<title>
sets the title of the page.<body>
contains the visible page content.
Why using meta tags?¶
Meta tags are a great way for webmasters to provide search engines and browsers with Additional information about their sites.
https://support.google.com/webmasters/answer/79812
Setting the viewport¶
width=device-width
: the width of the page matches the screen widthinitial-scale=1.0
: the initial zoom level
The Open Graph protocol¶
The Open Graph protocol defines common properties for the meta element. With these properties web pages become rich objects on the Web graph.
Search Engine Optimization (SEO)¶
Search engines use opaque and complex algorithms to rank web pages based on their contents.
Search Engine Optimization (SEO) is the art of pleasing these algorithms:
- Use the right tags
- Structure tags properly
- Provide relevant metadata
- and more...
Because these algorithms evolves constantly, so does SEO.
Notes:
Checkout this cheat sheet on SEO, made by Jordan Chenevier-Truchet (@jordanchenevier), if you want to know more.
HTML Elements¶
Anatomy of an HTML element¶
Notes:
An HTML element: - starts with an opening tag - may have some content - stops with a closing tag
Attributes of an element¶
Attributes are a key-value pair, specified in the opening tag.
They give more information about the element, for example
- the
id
attribute gives an identifier to the element that is unique in the document, - the
class
attribute assigns a class to the element, usually used to style it, - the
style
attribute provides CSS properties to style the element.
Notes:
The format of an attribute is always name="value"
.
Text elements¶
Headings:
Paragraph:
Line break:
Horizontal line:
Formatting:
Hyperlink element¶
Specifies a hyperlink to another location.
href
: URL of the linked webpagetitle
: text to display as a tooltip when hovering over the linktarget
: where to open the linked document (e.g.,_blank
opens the document in a new tab)
Media elements¶
The image element must have an src
(image url) and alt
(caption of the image) attribute.
The audio element requires special permissions to autoplay.
The canvas element allows for dynamic, scriptable rendering of 2D and 3D shapes.
Notes:
It is very bad practice to ommit the alt
attribute of an image. In addition to being displayed when hovering over the image, it is used by screen readers to describe the image to visually impaired users. Accessibility is a crucial aspect of web development.
Nested lists¶
Numbered lists and enumerations can be nested.
ol
is the root tag for ordered listsul
is the root tag for unordered listsli
is a list item
Tables¶
Tables should only be used for tabular data, not for layout.
tr
is a table rowtd
is a table data, i.e. a regular cellth
is a table header, i.e. a header cell
The colspan
and rowspan
attributes are used to merge cells.
HTML Forms¶
HTML Forms are one of the main points of interaction between a user and a web site or application. Forms allow users to enter data, generally sending that data to the web server.
The <form>
element defines a form.
- The
action
attribute defines the location (URL) where the form should be sent when it is submitted. - The
method
attribute defines which HTTP method to send the data with (it can be "get" or "post").
https://developer.mozilla.org/en-US/docs/Learn/HTML/Forms/Your_first_HTML_form
HTML Input Element¶
There exist many types of input elements, each with its own behavior and set of attributes.
Some of the available types are: text
, password
, submit
, hidden
, radio
, checkbox
, file
, email
, url
, date
, url
, etc.
Common attributes are
name
: the name of the input, which is submitted with the form data.value
: the default value of the input.placeholder
: the text that appears within the input when empty.required
: indicates that the input is mandatory. Submission will be blocked if the input is empty.readonly
: indicates that the input cannot be edited.
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input
Semantic elements¶
Header:
Navigation:
Main (dominant content of the body):
Footer:
Division (content block):
Article (self-contained composition in a document):
Section (generic content block):
Aside (content related to the main content):
Notes:
Using semantic elements is important for accessibility and SEO, because it helps screen readers and search engines to understand the structure of the page.
A growing list of elements¶
https://developer.mozilla.org/en-US/docs/Web/HTML/Element
HTML Entities¶
A character sequence that begins with an ampersand (&) and ends with a semicolon (;), used to describe special or reserved characters.
Character | Entity | Note |
---|---|---|
& | & | Interpreted as the beginning of an entity or character reference. |
< | < | Interpreted as the beginning of a tag. |
> | > | Interpreted as the end of a tag. |
" | " | Interpreted as the beginning or end of an attribute value. |
https://developer.mozilla.org/en-US/docs/Glossary/Entity