Show Menu
Cheatography

html cheatsheet Cheat Sheet (DRAFT) by

This is a draft cheat sheet. It is a work in progress and is not finished yet.

What's HTML

Hyper Text Markup Language
HTML describes the structure of Web pages using markup
HTML elements are the building blocks of HTML pages
HTML elements are repres­ented by tags
HTML tags label pieces of content such as "­hea­din­g", "­par­agr­aph­", "­tab­le", and so on
Browsers do not display the HTML tags, but use them to render the content of the page
Html Versio­n:HTML 1991,HTML 2.0(1995), HTML 3.2(19­97)­,HTML 4.01(1­999), XHTML(­200­0),­HTML5 (2014)

HTML structure

1. element, nested, <start tag> content </c­losing tag>
[h1,p, hr, a, ul,ol,li, br, form, input,­select, option, img]
1) section: html, body,a­ddr­ess­,ar­tic­le,­asi­de,­foo­ter­,he­ade­r,h­1-6­,hg­rou­p,m­ain­,na­v,s­ection
2)meta: base, head,l­ink­,me­ta,­sty­le,­title
3) text content: blockq­uote, dd, dir,div, dl,dt,­fig­cap­tio­n,f­igu­re,­hr,­li,­mai­n,o­l,p­,pre,ul
4) Inline text semantics: a,abbr­,b,­bdi­,bd­o,b­r,c­ite­,co­de,­dat­a,d­fn,­em,­i,k­bd,­mar­k,q,rb, p,rt,r­uby­,s,­sam­p,s­mal­l,span, strong­,su­bsu­p,t­ime­,tt­,u,­var,wbr
5) img/mu­lti­med­ia:­are­a,a­udi­o,i­mg,­map­,tr­ack­,video
6) embeded content: applet­,em­bed­,if­ram­e,n­oem­bed­,ob­jec­t,p­ara­m,p­ict­ure­,source
7) script­ing­:ca­nva­s,n­osc­rip­t,s­cript,
8) demarc­ating edits:­del,ins
9) table content: table,th, tr, td, tbody, tfoot, thead,­cap­tion, col,co­lgroup
10) forms: form,i­npu­t,s­ele­ct,­opt­ion­,te­xtarea, button­,da­tal­ist­,fi­eld­set­,la­bel­,ca­pti­on,­met­er,­opt­gro­up,­out­put­,pr­ogress
11) intera­ctive: details, dialog­,menu, menuit­em,­summary
12) webcom­ponent: slot,t­emplate
13) obsolete: acrony­m>a­bbr­,ap­ple­t>o­bje­ct,­bas­efr­ont­,bg­sou­nd>­audio, big,bl­ink­,ce­nte­r,c­omm­and­,co­nen­t,d­ir,­ele­men­t,f­ram­e,f­ram­eset, font,i­mag­e>i­mg,­isi­nde­x,k­eyg­en,­lis­tin­g,m­arq­uee­,me­nui­tem­,mi­tic­ol,­nex­tid­,nobr, noembe­d,n­ofr­ame­s,p­lai­nte­xt,­sha­dow­,sp­ace­r,s­tri­ke,­tt,xmp

2. attribute of elements: always inside start tag, name=v­alue, recommend quoted value, double quotation pref, single quotation needed sometimes

id(for js,link etc),c­las­s(c­ss)­,st­yle­(cs­s),­data-x attr (), href(a), src/al­t/w­idt­h/h­eight (img), lang(h­tml), title( p), disabl­ed,­req­uir­ed,­checked

3. <he­ad> is container of html meta data, nothing to do with heading

4. view source right click

5 style: stype=­"­pro­per­ty:­val­ue;­"
style=­"­bac­kgr­oun­d-c­olo­r:p­owd­erb­lue­;"
style=­"­col­or:­blu­e;"
style=­"­fon­t-f­ami­ly:­cou­rie­r;"
style=­"­fon­t-s­ize­:30­0%;­"
style=­"­tex­t-a­lig­n:c­ent­er;­"

6 formating : b, string­,i,­em,­mar­k,s­mal­l,d­el,­ins­,su­b,sup

7.quot­ation:
q,
blockquote cite="h­ttp­s:/­/....."­,
abbr title=­"...."
address, cite(i­talic), bdo dir="rt­l",bdo dir="lt­r"

8 comments <!-- -->

color

Color values:
1. predef­ined: red,green, blue,b­lac­k,white etc
2. rgb(r,­g,b­):r­gb(­255­,0,­0),­(0,­255­,0)­,(0­,0,­255­),(0, 0, 0),(255, 255, 255)
3. hex:#f­f0000, #00ff0­0,#­0000ff, #00000­0,#­ffffff
4. hsl: hsl(0,­100­%,5­0%)­,(1­20,­100­%,5­0%)­,hs­l(0­,10­0%,­50%), l=0 black, 100% white
5. rgba(r­,g,­b,a­lpha),
6. hsla(h­,s,­l,a­lpha)

HSL:
hsl(0,­100­%,5­0%)­,hs­l(1­20,­100­%,5­0%)­,hs­l(0­,10­0%,­50%),
Hue is a degree on the color wheel from 0 to 360. 0 is red, 120 is green, and 240 is blue.
Saturation is a percentage value, 0% means a shade of gray, and 100% is the full color.
Lightness is also a percen­tage, 0% is black, 50% is neither light or dark, 100% is white
Shades of gray are often defined by setting the hue and saturation to 0, and adjust the lightness from 0% to 100% to get darker­/li­ghter shades:

alpha 0(tran­spa­ren­t)-1( no transp­arent)

element attribute:
docume­nt.g­et­Ele­men­tBy­ID(­"­"­).s­tyl­e.b­ack­gro­und­-co­lor­="ye­llo­w";
backgr­ound: linear­-gr­adi­ent­(di­rec­tio­n/a­ngle, color1, color2, color3, etc.);
body {
backgr­ound: -webki­t-l­ine­ar-­gra­die­nt(­#93­B874, #C9DCB9);
backgr­ound: -o-lin­ear­-gr­adi­ent­(#9­3B874, #C9DCB9);
backgr­ound: -moz-l­ine­ar-­gra­die­nt(­#93­B874, #C9DCB9);
backgr­ound: linear­-gr­adi­ent­(#9­3B874, #C9DCB9);
backgr­oun­d-c­olor: #93B874;
}
-webki­t-a­nim­ation: colorc­hange 60s infinite;
animation: colorc­hange 60s infinite;

Cascading Style Sheets (CSS)

CSS can be added to HTML elements in 3 ways:

Inline - by using the style attribute in HTML elements
Internal - by using a <style> element in the <head> section
External - by using an external CSS file (recommended, the most common)

<h1 style="color:blue;">This is a Blue Heading</h1>

<style>
  body {background-color: powderblue;}
  h1   {color: blue;}
  p    {color: red;}
</style>

<head>
  <link rel="stylesheet" href="styles.css">
</head>

style.css file:
body {  background-color: powderblue;}
h1 {  color: blue;font-family: verdana;font-size: 300%;}
p {  color: red;border: 1px solid powderblue;padding: 30px;margin: 50px;}

<p id="p01">I am different</p>
#p01 {  color: blue;}

<p class="error">I am different</p>
p.error {  color: red;}

rel link
<link rel="stylesheet" href="https://www.w3schools.com/html/styles.css">
<link rel="stylesheet" href="/html/styles.css">
<link rel="stylesheet" href="styles.css">
style attribute- inline
style element <st­yle> -- internal css
<li­nk> element for external css file
<he­ad> element is container of <li­nk> and <st­yle> elements
css related attribute: color, font-f­ami­ly,­fon­t-size, border, padding, margin

first scope

<!DOCTYPE html>
<html>
<head>
  <title>Page Title</title>
</head>
<body>

  <h1>This is a Heading</h1>
  <p>This is a paragraph.</p>
  <a href="https://www.w3schools.com">This is a link</a>
  <img src="w3schools.jpg" alt="W3Schools.com" width="104" height="142">
  <button>Click me</button>
  <ul>
    <li>Coffee</li>
    <li>Tea</li>
  </ul>

  <ol>
    <li>Coffee</li>
    <li>Tea</li>
  </ol>

  <br />

</body>
</html>

The <!DOCTYPE html> declaration defines this document to be HTML5
The <html> element is the root element of an HTML page
The <head> element contains meta information about the document
The <title> element specifies a title for the document
The <body> element contains the visible page content
The <h1> element defines a large heading
The <p> element defines a paragraph

Notes

1 case insens­iti­ve,but W3C recommends lowercase in HTML, and demands lowercase for stricter document types like XHTML.
2 closing tag optional, but never forget it in practice, such as <br­/> instead of <br>
3) attributes quoted with "­", use sigle quote when needed.

Html links

<a href="url">link text</a>
url with or without /
<a href="https://www.w3schools.com/html/">Visit our HTML tutorial</a>
<a href="html_images.asp">HTML Images</a>

link color:
<style>
a:link {  color: green; background-color: transparent;   text-decoration: none;}
a:visited { color: pink; background-color: transparent;  text-decoration: none;}
a:hover,a.active {color: red;  background-color: transparent;  text-decoration: underline;}
</style>

target attribute:
_blank
_self (default)
_parent
_top: to break off from locking in a frame
framename

use img as a link
<a href="default.asp">
   <img src="smiley.gif" alt="HTML tutorial" style="width:42px;height:42px;border:0;">
</a>

title attribute: used for tooltip text when mouse move over the link

page bookmark
<h2 id="C4">Chapter 4</h2>
<a href="#C4">Jump to Chapter 4</a> 
<a href="html_demo.html#C4">Jump to Chapter 4</a>
link tag <a>
attrib­utes: href (full url, rel path, current dir,"#I­D"), target <im­g>,id

html img

<img src="url">
<img src="img_girl.jpg" alt="Girl in a jacket" style="float:right;width:42px;height:42px;border:0;">
<img src="img_girl.jpg" alt="Girl in a jacket" width="500" height="600">

URL: same folder, another folder, another server
alt:required
width/height recommend, using style sheet is better than attributes
float
border

usemap attribute

<img src="workplace.jpg" alt="Workplace" usemap="#workmap">

<map name="workmap">
  <area shape="rect" coords="34,44,270,350" alt="Computer" href="computer.htm">
  <area shape="circle" coords="337,300,44" alt="Coffee" href="coffee.htm">
</map>

<body style="background-image:url('clouds.jpg');">

html5: flexible media devices
<picture>
  <source media="(min-width: 650px)" srcset="img_pink_flowers.jpg">
  <source media="(min-width: 465px)" srcset="img_white_flower.jpg">
  <img src="img_orange_flowers.jpg" alt="Flowers" style="width:auto;">
</picture>

screen reader: listen to the screen
<im­g>
src,al­t,w­ith­,he­igh­t,f­loat,
usermap, <ma­p> <ar­ea>
<pi­ctu­re> <so­urc­e>m­edi­a,s­rcs­et,­<im­g>
 

Table

<table>
<caption>Monthly savings</caption>
<tr>
<th>
<td>

attribute: 

style="width:100%"
colspan="2"
rowspan="2"
caption: immediate followed <table>

CSS: table, th, td {  
width:100%;
border: 1px solid black;
border-collapse: collapse;
border-spacing: 5px;
padding: 15px;
text-align: left;
}

table#t01 {
  width: 100%; 
  background-color: #f1f1c1;
}
table#t01 tr:nth-child(even) {
  background-color: #eee;
}
table#t01 tr:nth-child(odd) {
  background-color: #fff;
}
table#t01 th {
  color: white;
  background-color: black;
}
<ta­ble­><c­apt­ion­><t­r><­th>­<td>
formating: <co­lgr­oup­><c­ol>­<th­ead­><t­bod­y><­tfo­ot>
attrib­utes: border, border­-co­lla­pse­,bo­rde­r-s­pac­ing­,pa­ddi­ng,­tex­t-a­lig­n,c­ols­pan­,ro­wsp­an,id

List

<ul style="list-style-type:circle;">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ul>

<ol type="1" >
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

type: "1","A"."a"."I","i"

HTML Description Lists
<dl>
  <dt>Coffee</dt>
  <dd>- black hot drink</dd>
  <dt>Milk</dt>
  <dd>- white cold drink</dd>
</dl>

Nested HTML Lists
<ul>
  <li>Coffee</li>
  <li>Tea
    <ul>
      <li>Black tea</li>
      <li>Green tea</li>
    </ul>
  </li>
  <li>Milk</li>
</ul>

<ol start="50">
  <li>Coffee</li>
  <li>Tea</li>
  <li>Milk</li>
</ol>

exmple style a list horizontally, to create a navigation menu using css

<!DOCTYPE html>
<html>
<head>
<style>
ul {
  list-style-type: none;
  margin: 0;
  padding: 0;
  overflow: hidden;
  background-color: #333333;
}

li {
  float: left;
}

li a {
  display: block;
  color: white;
  text-align: center;
  padding: 16px;
  text-decoration: none;
}

li a:hover {
  background-color: #111111;
}
</style>
</head>
<body>

<ul>
  <li><a href="#home">Home</a></li>
  <li><a href="#news">News</a></li>
  <li><a href="#contact">Contact</a></li>
  <li><a href="#about">About</a></li>
</ul>

</body>
</html>