9/10/23 Updated: Initial version of HTML note is finished.
9/18/23 Updated: New features of HTML5 are added.
Resources
Global Attributes Docs from MDN
HTML Basic Knowledge
Charset
How Computer Treats with Data:
Encoding Data
when computer is storing file.Decoding Data
when computer is reading file.
Both rules will follow charset defined such as UTF-8, GBK, ISO 8859-1.
Storing & Opening Rules:
- When we are storing a text file in Chinese with an unsuitable charset such as ISO 8859-1, the data inside will become
question-mark
; they will be lost. Cannot Recover! - When we are opening a text file with different encoding method, we will see unrecognized sections in the data file. Reopening with the Correct Charset Fixes the Issue!
HTML Structure
<!--HTML5 Declaration--> |
Special Tags
-
<br>:
New Line -
<hr>:
Separator Line -
<pre>:
Keep format of the code
<pre> |
Block & Inline Elements
References
Block & Inline Elements from W3Schools
Definitions
Block Elements:
A block-level element always starts on a new line, and the browsers automatically add some space (a margin) before and after the element.Inline Elements:
An inline element does not start on a new line, and only takes up as much width as necessary.
Using Rules
-
Block Elements
can almost haveInline Elements
andBlock Elements
inside. Programmer can write anything inside it except under some special rules.<p>
,<div>
,<h1> - <h6>
, …
-
Inline Elements
can only haveInline Elements
, and they cannot haveBlock Elements
.<span>
,<input>
, …
-
Special Rules:
-
<h1> - <h6>
cannot be embedded with each other inside. For example:<h1>
<h2>
Hello, world!
</h2>
</h1> -
<p>
cannot haveBlock Elements
inside. -
… (More will be learned in the future)
-
Text Tags
<em>:
emphasize reading content.<strong>:
important content (stronger than<em>
).<span>:
no meaning; it’s just a genral wrapper.
The Text tags
are usually inline elements. But some like blockquote
and address
are block elements.
Image Tags
Attributes
src:
the photo path.alt:
the description of the photo.width:
the width px of the photo.height:
the height px of the photo.
The image will remain the ratio between width and height unless user change both of them.
“alt” Usage
- Good for
SEO
since when the search engine reads thealt
attribute, it will know the content of the image. - When the image cannot be loaded normally, some brower will display the value of
alt
. - The reading aid for blind can read the value of
alt
to let people knows.
Image Formats
First Part of Related Tutorial from atguigu
Second Part of Related Tutorial from atguigu
-
.jpg or .jpeg:
a kind of lossy compressing format- Does not support transparent background and dynamic pictures.
- For those environments that don’t require extremely high quality of the image.
-
.png:
a kind of lose-less compressing format- Supports transparent background.
- Higher image quality than
.jpeg
. - Company logo image or important images.
-
.gif:
Mainly for dynamic images- Supports only 256 colors, and simple transparent background.
-
.webp:
an image format developed for the website- Some old browsers do not support this kind of file extension.
- Equipped with all advantages that other images have.
-
base64:
a string of special text that the image is encoded by methodbase64
- Only browser can recognize it and convert it to the image.
- We can use
base64
to encode some small images.
HyperLink <a>
General
<!-- Open new tab to jump to the other website --> |
<a>
isinline element
but it can embed all other elements except itself.- Multiple spaces or newlines will be rendered as one space.
Jump to Anchor
Setup Anchors
<!-- 1. using tag <a> with attribute "name" --> |
Jumping
<!-- jump to test1 --> |
Jump to Application
<!--Call--> |
List
General
It is better not to use <li>
out of a list although it behaves like unordered list.
Usage
<ol>:
Ordered List
<ol> |
<ul>:
Unordered List
<ul> |
<dl>:
Defined Listdefined title(term)
:defined data
<h2>Hello</h2> |
Table
General
A complete Table <table>
is consist of four parts:
- Table Caption
<caption>
- Table Header
<thead>
- Row
<tr>
- Header Cell
<th>
- Header Cell
- Row
- Table Body
<tbody>
- Row
<tr>
- Data Cell
<td>
- Data Cell
- Row
- Table Foot
<tfoot>
- Row
<tr>
- Data Cell
<td>
- Data Cell
- Row
<table> |
Attributes
Tag Name | Tag Meaning | Attributes |
---|---|---|
<table> |
table | width: the width of the table. height: the minimum height of the table, and the final height may be higher. border: set the width of the table. cellspacing : the space between cells. |
<thead> |
table header | height: the height of the table header. align: the way to align cell horizontally; 1) left 2) center 3) right. valign: the way to align cell vertically; 1) top 2) middle 3) bottom |
<tbody> |
table body | Same as <thead> |
<tr> |
table row | Same as <thead> |
<tfoot> |
table footer | Same as <thead> |
<td> |
table data cell | width: the width of the cell, and all same column cells will be effected. height: the height of the cell, and all same row cells will be effected. align: the way to set the cell alignment horizontally. valign: the way to set the cell alignment vertically. rowspan: indicate the number of rows being combined. colspan: indicate the number of columns being combined. |
<th> |
table header cell | Same as <td> |
<table border="1" width="300" height="600" cellspacing="0"> |
Form
General
<form>:
form body"action":
indicate the address that form will be sent."target":
control the way about how to open the page"_self":
open in the local tab"method":
control the method that how the form will be sent. GET, POST,…
<input>:
input areatype:
the type of input"text"
"radio:"
can setdisabled
,checked
"password"
"checkbox:"
can setdisabled
,checked
"hidden":
it will not be shown, and it’s only for some fixed field"submit":
submit the form to theaction
"reset":
reset all elements inside the form"button":
normal button
name:
the field name that will be submittedvalue:
the default field valuemaxlength:
the maximum length that can be input
<button>:
default is “submit”
Other elements
Select
<select name="from"> |
Textarea
<textarea name="msg" rows="22" cols="3">TEXTAREA</textarea> |
Label
When we want the effect that clicking the field name makes the cursor focusing on that field input, <label>
is useful.
First Method
<label for="account">Account</label> |
Second Method
<label> |
Fieldset & Legend
<fieldset>
can classify the form elements, and <legend>
is the titile of the type.
<fieldset> |
Iframe
General
<iframe>:
Embedding other websites or files into the website
name:
the name of theiframe
which can work with the attributetarget
(shown below).width:
the width of theiframe
window.height:
the height of theiframe
window.frameborder:
whether shows border;0
or1
.
Usage
<!-- Embedding a normal website --> |
Applications
- Embedding AD into the website.
- Working with the attribute
target
of hyperlink and form to express different contents.
H5 General
HTML5
is latest HTML
standard created on 10/2014 by W3C.
Advantages
- Implemented a lot of useful interfaces for
javascript
. - Added more semantic labels and global attributes.
- Updated multi-media supports which will perfectly replace
flash
. - Focused more on semantization which is beneficial for
SEO
. - Provided a better method to adapt on or migrate to mobile devices.
Compatibility
Supported Chrome
, Safari
, Opera
, Firefox
.
IE
browser must have version 9 and above that can support H5
, and version 9 can only support part of H5
.
H5 Semantic Labels
header:
The header of the whole page or the part.footer:
The footer of the whole page or the part.nav:
The navigation part.article:
The article, blog, news, comments, and etc.section:
A paragraph or a part of words in a page.aside:
The aside bar.
About article
and section
article
can have multiplesection
inside.section
emphasizes part and section; it is suggested to usesection
if the content will be splited into multiple parts.article
focuses more on independency; so it is better to usearticle
if the content is complete and independent.
H5 Status Labels
Label Meter
General
meter
is used for measuring conditions such as battery usage, disk usage; it can also be called gauge
.
Attributes
high:
The high value.low:
The low value.max:
The maximum value.min:
The minimum value.optimum:
The optimum value; if its value is set, which means the two closed gauges will be regarded as optimum.value:
The current value.
Label Progress
General
progress
is used for indicating the progress of a task such as work task.
Attributes
max:
The goal value.
value:
The current value.
H5 List Labels
datalist:
Used for keywords hint in search bar.details:
Used for showing questions and answers, or explaining the term.summary:
Written indetails
to indicate the question or the term.
<input type="text" list="mydata"> |
<details> |
H5 Text Labels
ruby:
Used for wrapping words that need annotations.rt:
Annotation written inruby
.
<ruby> |
mark:
Used for marking the keywords obtained from the searching result.
H5 Form Element Attributes
placeholder:
Used for hinting words.- It is not the default value (attribute
value
is default one) - It is appropriate for texting input element.
- It is not the default value (attribute
required:
The input element is mandatory with value.autofocus:
Automatically focus on the input element when open the page.autocomplete:
Automatically complete the texting input element.- Set with
on
oroff
. password
andtextarea
are not suitable.
- Set with
pattern:
Used for regular expression to validate the value input in.textarea
and empty element will no be validated.required
is usually used together.
H5 Input Types & Attributes
- The input element can be one of the following types:
email
,url
,number
,search
,tel
,range
,color
,date
,month
,week
,time
,datetime-local
. Check here for details. novalidate:
Ifform
is set with this attribute, theform
will not be validated.
H5 Video Label
<video>
is used for define video.
-
src:
URL address for the video. -
width/height:
The width/height of the video. -
controls:
Show user about the video widgets. -
muted:
Mute the video. -
autoplay:
automatically play the video except it hasmuted
; but if the media engagement of this website is high enough, it is possible to autoplay the video withoutmuted
. -
loop:
Play the video periodically. -
poster:
The url of the cover of the video. -
preload:
Preload the video. But it will be disabled by using it withautoplay
.auto:
Let browser decide how much video should be preloaded.metadata:
Only preload metadata of the video.none:
Do not preload video.
H5 Audio Label
<audio>
is used for defining audio.
src:
URL address for the audio.controls:
Show user about the audio widgets.muted:
Mute the audio.autoplay:
automatically play the audio.loop:
Play the audio periodically.preload:
Preload the audio. But it will be disabled by using it withautoplay
.auto:
Let browser decide how much audio should be preloaded.metadata:
Only preload metadata of the audio.none:
Do not preload audio.
H5 Global Attributes
contenteditable:
Indicate if the element can be editable.true
/false
draggable:
Indicate if the element can be dragged.true
/false
hidden:
Hide the element without keeping space.spellcheck:
Set if spell check will be applied to the element.true
/false
contextmenu:
Shows when users right click their mouse. It is used for customized right click menu.data-*:
Used for storing customized page data; it is for js in the future.
H5 Compatibility
<!-- Set IE always using latest mode to render --> |
html5shiv.js
is developed by Google in order to realize partial features of HTML5
on old browsers.
<!--[if lt ie 9]> |
lt
less than.lte
less than and equal to.gt
greater than.gte
greater than and equal to.!
logical negate.