Basic HTML and HTML5
Basic HTML and HTML5
<h1> Tag
<h2> Tag
<p> Tag
e.g. <p>I'm a p tag!</p>
Comments in HTML
Comments in HTML starts with <!-- , and ends with a -->
HTML5 Elements
HTML5 introduces more descriptive HTML tags. These include header, footer, nav, video,
article, section and others.
These tags make your HTML easier to read, and also help with Search Engine Optimization (SEO) and
accessibility.
The main HTML5 tag helps search engines and other developers find the main content of your page.
Images
Note that img elements are self-closing.
e.g.
<img src="https://www.your-image-source.com/your-image.jpg" alt="Author
standing on a beach with two thumbs up.">
Anchor Element
1. External Link
e.g.
<a href="https://freecodecamp.org">this links to freecodecamp.org</a>
2. Internal Link
e.g.
<a href="#contacts-header">Contacts</a>
...
<h2 id="contacts-header">Contacts</h2>
3. Dead Link
e.g.
href="#"
Unordered List
e.g.
<ul>
<li>milk</li>
<li>cheese</li>
</ul>
Ordered List
e.g.
<ol>
<li>Garfield</li>
<li>Sylvester</li>
</ol>
Text Field
e.g.
<input type="text">
1. Placeholder Text
e.g.
<input type="text" placeholder="this is placeholder text">
Form Element
e.g.
<form action="/submit-cat-photo">
<input type="text" placeholder="cat photo URL">
</form>
1. Submit Button
<form action="/submit-cat-photo">
<input type="text" placeholder="cat photo URL">
<button type="submit">submit</button>
</form>
2. Required Field
<form action="/submit-cat-photo">
<input type="text" placeholder="cat photo URL" required>
<button type="submit">Submit</button>
</form>
Radio Element
<label for="indoor">
<input id="indoor" type="radio" name="indoor-outdoor">indoor
</label>
Checkboxes
e.g.
<label for="loving">
<input id="loving" type="checkbox" name="personality">loving
</label>
<label>
<input type="radio" name="indoor-outdoor" checked>Indoor
</label>
Div
e.g.
<div>
<p>Things cats love:</p>
<ul>
<li>cat nip</li>
<li>laser pointers</li>
<li>lasagne</li>
</ul>
</div>
<h2 style="color:red;">CatPhotoApp</h2>
e.g.
<style>
.red-text {
color: red;
}
p{
font-size: 16px;
}
</style>
p {
font-size: 16px;
font-family: monospace;
}
</style>
<style>
h2{
font-family: Lobster;
}
</style>
There are several default fonts that are available in all browsers. These
generic font families include monospace, serif and sans-serif
When one font isn't available, you can tell the browser to "degrade" to
another font.
For example, if you wanted an element to use the Helvetica font, but degrade
to the sans-serif font when Helvetica wasn't available, you will specify it as
follows:
p {
font-family: Helvetica, sans-serif;
}
Generic font family names are not case-sensitive. Also, they do not need
quotes because they are CSS keywords.
<style>
.smaller-image{
width: 100px;
}
</style>
...
<a href="#"><img class="smaller-image" src="https://bit.ly/fcc-relaxing-cat"
alt="A cute orange cat lying on its back."></a>
Remember that you can apply multiple classes to an element using its class
attribute, by separating each class name with a space. For example:
Note: this challenge allows for multiple possible solutions. For example, you
may add border-radius to either the .thick-green-border class or the .smaller-
image class.
</form>
#cat-photo-form{
background-color: green;
}
...
<form action="/submit-cat-photo" id="cat-photo-form">
[type='radio']{
margin: 10px 0px 15px 0px;
}
--penguin-skin: gray;
--penguin-belly: white;
--penguin-beak: orange;
}
When using your variable as a CSS property value, you can attach a fallback
value that your browser will revert to if the given variable is invalid.
Note: This fallback is not used to increase browser compatibilty, and it will
not work on IE browsers. Rather, it is used so that the browser has a color to
display if it cannot find your variable.
When your browser parses the CSS of a webpage, it ignores any properties that
it doesn't recognize or support. For example, if you use a CSS variable to
assign a background color on a site, Internet Explorer will ignore the
background color because it does not support CSS variables. In that case, the
browser will use whatever value it has for that property. If it can't find any
other value set for that property, it will revert to the default value, which
is typically not ideal.
This means that if you do want to provide a browser fallback, it's as easy as
providing another more widely supported value immediately before your
declaration. That way an older browser will have something to fall back on,
while a newer browser will just interpret whatever declaration comes later in
the cascade.
.red-box {
background: red; -------- Added Text to improve compatibility
background: var(--red-color);
height: 200px;
width:200px;
}
For instance, when your screen is smaller or larger than your media query
break point, you can change the value of a variable, and it will apply its
style wherever it is used.
:root {
--penguin-size: 300px;
--penguin-skin: gray;
--penguin-belly: white;
--penguin-beak: orange;
}
}
}
text-align: justify; causes all lines of text except the last line to meet the left and right
edges of the line box.
<p>Google was founded by Larry Page and Sergey Brin while they were Ph.D.
students at <strong>Stanford University.</strong></p>
<p>Google was founded by Larry Page and Sergey Brin while they were <u>Ph.D.
students</u> at <strong>Stanford University</strong>.</p>
<p><em>Google was founded by Larry Page and Sergey Brin while they were
<u>Ph.D. students</u> at <strong>Stanford University</strong>.</em></p>
<hr>
h4 {
font-size: 27px;
}
The box-shadow property takes values for offset-x (how far to push the shadow horizontally
from the element), offset-y (how far to push the shadow vertically from the element), blur-
radius, spread-radius and a color value, in that order. The blur-radius and spread-
radius values are optional.
Here's an example of the CSS to create multiple shadows with some blur, at mostly-transparent
black colors:
.thumbnail{
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
}
.links {
opacity: 0.7;
}
The following table shows how the different text-transform values change the example text
"Transform me".
Value Result
lowercase "transform me"
Value Result
uppercase "TRANSFORM ME"
capitalize "Transform Me"
initial Use the default value
inherit Use the text-transform value from the parent element
none Default: Use the original text
h4 {
text-transform: uppercase;
}
p {
font-size: 16px;
line-height: 25px;
}
a {
color: #000;
}
a:hover{
color: red;
}
#navbar {
position: fixed;
}
The next positioning tool does not actually use position, but sets the float
property of an element. Floating elements are removed from the normal flow of
a document and pushed to either the left or right of their containing parent
element. It's commonly used with the width property to specify how much
horizontal space the floated element requires.
#left {
float: left;
width: 50%;
}
When elements are positioned to overlap, the element coming later in the HTML
mark-up will, by default, appear on the top of the other elements. However,
the z-index property can specify the order of how elements are stacked on top
of one another. It must be an integer (i.e. a whole number and not a decimal),
and higher values for the z-index property of an element move it higher in the
stack than those with lower values.
.first {
z-index: 2;
}
Center an Element Horizontally Using the margin Property
This method works for images, too. Images are inline elements by default, but
can be changed to block elements when you set the display property to block.
div {
margin: auto;
}
div{
background: linear-gradient(35deg, #CCFFFF, #FFCCCC);
}
The angle value is the direction of the gradient. Color stops are like
width values that mark where a transition takes place, and are given with
a percentage or a number of pixels.
In the example demonstrated in the code editor, the gradient starts with
the color yellow at 0 pixels which blends into the second color blue at 40
pixels away from the start. Since the next color stop is also at 40
pixels, the gradient immediately changes to the third color green, which
itself blends into the fourth color value red as that is 80 pixels away
from the beginning of the gradient.
For this example, it helps to think about the color stops as pairs where
every two colors blend together.
If every two color stop values are the same color, the blending isn't
noticeable because it's between the same color, followed by a hard
transition to the next color, so you end up with stripes.
div{
background: repeating-linear-gradient(
45deg,
yellow 0px,
yellow 40px,
black 40px,
black 80px
);
}
#bottom {
transform: skewY(24deg);
}
Create a Graphic Using CSS
.center
{
background-color: transparent;
border-radius: 50%;
box-shadow: 25px 10px 0px 0px blue;
}
Create a More Complex Shape Using CSS and HTML
<style>
.heart {
position: absolute;
margin: auto;
top: 0;
right: 0;
bottom: 0;
left: 0;
background-color: pink;
height: 50px;
width: 50px;
transform: rotate(-45deg);
}
.heart::after {
background-color: pink;
content: "";
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: 0px;
left: 25px;
}
.heart::before {
content:"" ;
background-color: pink;
border-radius: 50%;
position: absolute;
width: 50px;
height: 50px;
top: -25px;
left: 0px;
}
</style>
<div class = "heart"></div>
<style>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
}
#rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow{
0%{
background-color: blue;
}
50%{
background-color: green;
}
100%{
background-color: yellow;
}
</style>
<div id="rect"></div>
<style>
button {
border-radius: 5px;
color: white;
background-color: #0F5897;
padding: 5px 10px 8px 10px;
}
button:hover {
animation-name: background-color;
animation-duration: 500ms;
}
@keyframes background-color {
100% {
background-color: #4791d0;
}
}
</style>
<button>Register</button>
div {
height: 40px;
width: 70%;
background: black;
margin: 50px auto;
border-radius: 5px;
position: relative;
}
#rect {
animation-name: rainbow;
animation-duration: 4s;
}
@keyframes rainbow {
0% {
background-color: blue;
left: 0px;
}
50% {
background-color: green;
left: 25px;
}
100% {
background-color: yellow;
left: -25px;
}
}
@keyframes bounce{
0% {
top: 0px;
}
50% {
top: 249px;
width: 130px;
height: 70px;
}
100% {
top: 0px;
}
}
#ball1 {
left:33%;
animation-timing-function: linear;
}
#ball2 {
left:66%;
animation-timing-function: ease-out;
}
How Bezier Curves Work
In CSS animations, Bezier curves are used with the cubic-bezier function.
The shape of the curve represents how the animation plays out. The curve
lives on a 1 by 1 coordinate system. The X-axis of this coordinate system
is the duration of the animation (think of it as a time scale), and the Y-
axis is the change in the animation.
The cubic-bezier function consists of four main points that sit on this 1
by 1 grid: p0, p1, p2, and p3. p0 and p3 are set for you - they are the
beginning and end points which are always located respectively at the
origin (0, 0) and (1, 1). You set the x and y values for the other two
points, and where you place them in the grid dictates the shape of the
curve for the animation to follow. This is done in CSS by declaring the x
and y values of the p1 and p2 "anchor" points in the form: (x1, y1, x2,
y2). Pulling it all together, here's an example of a Bezier curve in CSS
code:
In the example above, the x and y values are equivalent for each point (x1
= 0.25 = y1 and x2 = 0.75 = y2), which if you remember from geometry
class, results in a line that extends from the origin to point (1, 1).
This animation is a linear change of an element during the length of an
animation, and is the same as using the linear keyword. In other words, it
changes at a constant speed.