<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
All HTML files start with a doctype.
This doctype states HTML5 is being used.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
The html tags tell the browser where to begin and end.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Content placed within the head tags is not displayed.
Head tags store metadata. (Examples: a link to the site's CSS or a description of the site for search engines.)
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Content that will be displayed in the browser.
Container HTML Element
Self-Closing HTML Element
<tagname>Hello World</tagname>
<open>Hello World</close>
Paragraph
Heading
Google
<tagname attribute="value" attribute="value">
Mozilla Developer Network - preferred resource ✅:
https://developer.mozilla.org/en-US/docs/Web/HTML/ElementW3Schools:
https://www.w3schools.com/tagsIndenting nested tags is important because it helps us identify where a tag begins and ends. Browsers ignore these extra spaces.
How we see our code:
<body>
Indented paragraph tag
</body>
How the browser reads our code:
<body>Indented paragraph tag
</body>
Image from internetingishard.com
HTML tags that are Block elements: <p></p>, <li></li>, <h1></h1>
Example: <p> tag
Paragraph with a background color.
HTML tags that are Inline elements: <a></a>, <em></em>, <img>
Example: <em> tag
This paragraph uses the inline <em> tag to italicize text. See how it fits right in with the flow of the text?
Example: <a> tag
First Link Second LinkOpen Your Text Editor (Atom)
Steps to create an HTML file
File -> New File -> Save As -> index.html
Let's add a block element paragraph
Let's add an inline element
Open Chrome
File -> Open File -> index.html -> Open
Image from codercv.com
Structure vs Presentation
CSS stands for: Cascading Style Sheets
Cascading - CSS is written by defining "rules" and these rules can override each other. The "cascade" is responsible for determining which rule is applied to the HTML.
Style Sheets
- refers to a file containing CSS code.
This language is used to describe the presentation of a web page.
CSS can change colors, fonts, and the position of content.
Example of how CSS can change the appearance of content.Three ways to add CSS to HTML:
Use the HTML "style" attribute.
A paragraph with a background color.
A paragraph with a background color.
The "cascade" considers inline styles to be the highest priority. Inline styles are always applied over any other competing style.
However, Inline CSS styles:
Inline CSS styles - not recommended ❌
Use the <style> tag inside the <head> tags.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
This text will be blue.
</body>
</html>
Allows CSS to be defined in the same file as the HTML file.
However, Embedded CSS styles:
Embedded CSS styles - not recommended ❌
Use the <link> tag inside the <head> tags.
<!DOCTYPE html>
<html>
<head>
</head>
<body>
</body>
</html>
Separates the HTML from the CSS by writing CSS in a separate file.
External CSS styles:
External CSS styles - recommended! ✅
Image from internetingishard.com
Open the newly created index.html file.
Add the following HTML.
<!DOCTYPE html>
<html>
<head>
Hello, CSS
</head>
<body>
Hello, CSS
CSS lets us style HTML elements.
</body>
</html>
Open Chrome
File → Open File → index.html → Open
HTML | uses tags | < > |
CSS | creates rules | { } |
Image from internetingishard.com
In the file styles.css, add the following:
body {
background-color: blue;
}
Use the <link> tag to tell the HTML file to load a CSS file.
<head>
Hello, CSS
</head>
Breaking down the attributes...
body {
background-color: LightBlue;
}
body {
background-color: plum;
}
Colors can be referenced by:
Image from blog.hubspot.com
Approximately 147 color names are supported by all browsers.
A few examples include: LightBlue, Blue, Red, Purple, and Green.
In the styles.css file, change the background color to a different color.
For color name options, visit: colors.commutercreative.com/grid
body {
background-color: color-name-here;
}
A hex value (short for hexidecimal value) looks like this: #ADD8E6
Hex values are a unique code that represent a color. This unique code is composed of six characters, using numerals and letters.
The leading "#" symbol declares "this is a hex value".
In the styles.css file, change the background color to a different color using a hex value.
For color hex values, visit either site:
body {
background-color: color-hex-value-here;
}
Bonus:
Can you tell me if hex values case sensitive?
Does #add8e6 work the same as #ADD8E6?
The color property sets the font color.
To change the font color, select the body and set the property color to a color value (color name or hex value).
body {
background-color: color-value-here;
color: color-value-here;
}
To change the header font color, select the header tag and set the property color to a color value (color name or hex value).
h1 {
color: color-value-here;
}
The font-family property defines which typeface is used.
font-family accepts multiple values because not all browsers have the same fonts available.
In the example below, the browser tries to load the left-most value first (Helvetica), falls back to Arial if the font is not available and finally, chooses the system's default sans serif font.
p {
font-family: "Helvetica", "Arial", sans-serif;
}
Example of fonts on different systems:
There are five fonts that are truly universal:
Arial, Courier New, Georgia, Times New Roman, and Verdana
List of web safe font stacks: https://www.w3schools.com/cssref/css_websafe_fonts.asp
The small features on the ends of strokes are known as "serifs".
Image from about.easil.com
Common Serif typefaces include: Times New Roman, Georgia, Palatino and Garamond.
Common Sans Serif typefaces include: Arial, Helvetica and Tahoma.
Let's pick out a font stack!
Externally hosted fonts allow us to use fonts that our user's systems aren't likely to have installed.
A "px", or pixel, is a unit of measurement when discussing a graphical display, like a computer screen.
Screen display resolution is often expressed in the unit of pixels. Example: A "800 x 600" pixel resolution means that 800 pixels can be displayed in width and 600 pixels in height.
body {
font-size: 20px;
}
CSS Classes and IDs
Container Divs
CSS Box Model