• Stars
    star
    163
  • Rank 231,141 (Top 5 %)
  • Language
    HTML
  • License
    MIT License
  • Created almost 11 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

intro to html and css

Developed in conjunction with Thinkful.

thinkful

Come code along with me! Sign up here.


Introduction to HTML and CSS

Websites are made up of many things, but HTML (Hyper Text Markup Language) and CSS (Cascading Style Sheets) are two of the most important components. Together, they are the building blocks for every single webpage on the Internet.

Think of a car. It, too, is made up of many attributes. Doors. Windows. Tires. Seats. In the world of HTML, these are the elements of a webpage. Meanwhile, each of the car's attributes are usually different. Perhaps they differ by size. Or color. Or wear and tear. These attributes are used to define how the elements look. Back in the world of webpages, CSS is used to define the look and feel of a webpage.

Now let's turn to an actual web page ..

Requirements

Before we start, you need a source code editor, which is simply a text editor designed specifically for writing source code. Some popular editors include Notepad++ (Windows), TextMate (Mac), and Gedit (cross-platform). For this exercise, please download the cross-platform editor Sublime Text, which is an editor designed for simplicity and ease of use.

Also, please make sure you have Google Chrome installed.

HTML

HTML gives a web pages structure, allowing you to view it from a web browser:

Start by adding some basic structure:

<!DOCTYPE html>
<html>
  <head>
  </head>
  <body>
  </body>
</html>

Copy and paste this basic webpage structure into your text editor. Save this file as index.html.

This structure is commonly referred to as a boilerplate template. Such templates are used to speed up development so you don't have to code the features common to every single webpage each time you create a new page. Most boilerplates include more features (or boilerplate code), but let's start with the basics.

What's going on?

  1. The first line, <!DOCTYPE html> is the document type declaration, which tells the browser the version of HTML the page is using (HTML5, in our case). Without this, browsers can get confused, especially older versions of Internet Explorer.
  2. <html> is the first tag and it informs the browser that all code between the opening and closing, </html>, tags is HTML.
  3. The <head> tag contains links to CSS stylesheets and Javascript files that we wish to use in our web page, as well as meta information used by search engines for classification. In the above HTML, I used the <title> tag to give the web page a title.
  4. All code that falls within the <body> tags are part of the main content of the page, which will appear in the browser to the end user.

This is how a standard HTML page is structured.

Let's add four tags:

  1. title <title>
  2. heading <h1>
  3. img <img>
  4. break <br>
<!DOCTYPE html>
<html>
  <head>
  	<title>My bumblebee website</title>
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
  </body>
</html>

Open the page in Chrome; it should look like this:

html

Elements, Tags, and Attributes

  1. Tags form the structure of your page. They surround and apply meaning to content. There usually is an opening tag and then a closing tag, like - <div></div>, a divider. Again, we are using the following tags:
  • Title: <title> displays the title in the browser toolbar. It's also used for the title when its added to your browser's favorites and the title of your page for search engine results.
  • Headings: These include the <h1>, <h2>, <h3>, <h4>, <h5> and <h6> tags. <h1> is the main heading and the remaining headings decrease in size, with <h6> being the smallest. It's best practice to use the <h1> tag once per page, while the other tags can be used any number of times, but they should always be in order. In other words, <h3> should be a sub-heading of <h2> and <h4> should be a sub-heading of <h3>. Can you recognize the header in the HTML.
  • Some tags, like the <img> (image) and <br> (line break) tags do not require a closing tag. Notice how I included one <br> tag with a / on the end. This was a best practice in previous versions of HTML. HTML5, on the other hand - the version we are using - is much more relaxed and does not require a /, but it will work fine with it as well. It's really the developer's preference.
  1. Elements represent the tags as well as whatever falls between the opening and closing tags, like - <title>My bumblebee website</title>
  2. Attributes (sometimes referred to as selectors) are used to select the tag for some purpose. In our case we are going to use them for defining styles, when we get to CSS. Selectors in most cases are either ids or classes. In the above example, notice the id my-header, which is associated with the <h1> tag. We'll look more at this later. Further, we also use the attributes width="240" and height="180". These are defined using attributes directly within the HTML, or you can also place them in the CSS stylesheet. Again, more on this later.

Additional Tags

Two additional tags are lists (ordered <ol> and unordered <ul>) as well as links <a href>. Look these up on your own. Mozilla has an excellent reference guide here.

Putting it all together

Let's add all the tags that were discussed.

Headings

<h2>Wonder, wonderful bumblebees</h2>
<h2>About the Bumblebee</h2>
<h2>Types of Bees:</h2>
<h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>

Updated code:

<!DOCTYPE html>
<html>
  <head>
    <title>My bumblebee website</title>
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <h2>Wonder, wonderful bumblebees</h2>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
    <h2>About the Bumblebee</h2>
      <h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>
    <br>
    <h2>Types of Bees:</h2>
  </body>
</html>

Paragraph

Paragraphs: The <p> tag is used for splitting content literally into separate paragraphs. Each new <p> tag will appear on a new line.

<p>A bumblebee is any member of the bee genus Bombus, in the family Apidae. There are over 250 known species, existing primarily in the Northern Hemisphere although they also occur in South America. They have been introduced to New Zealand and the Australian state of Tasmania.</p>

Updated code:

<!DOCTYPE html>
<html>
  <head>
    <title>My bumblebee website</title>
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <h2>Wonder, wonderful bumblebees</h2>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
    <h2>About the Bumblebee</h2>
      <h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>
      <p>A bumblebee is any member of the bee genus Bombus, in the family Apidae. There are over 250 known species, existing primarily in the Northern Hemisphere although they also occur in South America. They have been introduced to New Zealand and the Australian state of Tasmania.</p>
    <br>
    <h2>Types of Bees:</h2>
  </body>
</html>

Ordered Lists

<ol>
  <li>Southern plains bumblebee</li>
  <li>New garden bumblebee</li>
  <li>Early bumblebee</li>
  <li>Orange-belted bumblebee</li>
  <li>Buff-tailed bumblebee or large earth bumblebee</li>
</ol>

Updated code:

<!DOCTYPE html>
<html>
  <head>
    <title>My bumblebee website</title>
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <h2>Wonder, wonderful bumblebees</h2>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
    <h2>About the Bumblebee</h2>
      <h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>
      <p>A bumblebee is any member of the bee genus Bombus, in the family Apidae. There are over 250 known species, existing primarily in the Northern Hemisphere although they also occur in South America. They have been introduced to New Zealand and the Australian state of Tasmania.</p>
    <br>
    <h2>Types of Bees:</h2>
      <ol>
        <li>Southern plains bumblebee</li>
        <li>New garden bumblebee</li>
        <li>Early bumblebee</li>
        <li>Orange-belted bumblebee</li>
        <li>Buff-tailed bumblebee or large earth bumblebee</li>
      </ol>
  </body>
</html>

Check it out in your browser. Add some more elements, or let's move on to CSS so we can make the site look better.

On to CSS ..

CSS

While HTML provides, structure, CSS is used for styling, making webpages look nice. From the size of the text to the background colors to the positioning of HTML elements, CSS gives you control over almost every visual aspect of a page.

CSS and HTML work in tandem. CSS styles (or rules) are applied directly to HTML elements. For example, remember this element from above - <h1 id="my-header">Bees!</h1>. Well, since there is an id selector associated with it, we can assign CSS styles to it using an external stylesheet.

#my-header {
  color: #660000;
}

Save this as "styles.css".

There are three ways that you can assign styles to HTML tags. Inline. Internal. Or External. Inline styles are placed directly in the tag; these should be avoided, though, as it's best practice to keep HTML and CSS styles separated (don't mix structure with presentation!). Internal styles fall within the head of a website. Again, these should be avoided as well due to reasons mentioned before. Read more about this here.

Next, we need to "link" our HTML page and CSS stylesheet. To do so, add the following code to the <head> section of the HTML page just below the title:

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

Your code should now look like this:

<!DOCTYPE html>
<html>
  <head>
    <title>My bumblebee website</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <h2>Wonder, wonderful bumblebees</h2>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
    <h2>About the Bumblebee</h2>
      <h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>
      <p>A bumblebee is any member of the bee genus Bombus, in the family Apidae. There are over 250 known species, existing primarily in the Northern Hemisphere although they also occur in South America. They have been introduced to New Zealand and the Australian state of Tasmania.</p>
    <br>
    <h2>Types of Bees:</h2>
      <ol>
        <li>Southern plains bumblebee</li>
        <li>New garden bumblebee</li>
        <li>Early bumblebee</li>
        <li>Orange-belted bumblebee</li>
        <li>Buff-tailed bumblebee or large earth bumblebee</li>
      </ol>
  </body>
</html>

Save the file. Check it out in your browser.

See the difference? Yes, it's subtle - but the <h1>, or main header, is a maroon color.

You can change certain elements even if they are not explicitly found within the HTML of the page, like the background color.

Update your CSS file:

body {
  background-color: #FFFF00
}

#my-header {
  color: #660000;
}

Save. Refresh.

What's going on?

Look back at the CSS file.

  1. We have the #my-header selector, which is associated with the selector in our HTML document, followed by curly braces.
  2. Inside the curly braces, we have properties, which are descriptive words, like font-weight, font-size, or background color. In our case, we have color.
  3. Values are then assigned to each property, which are preceded by a colon and followed by a semi-colon. http://cssvalues.com/ is an excellent resource for finding the acceptable values given a CSS property. I use this almost everyday.

Can you figure out what's going on with the body tag?

Additional Properties

You can view all the available properties here. Pay attention to the font-related properties - like font-family, font-weight, and font-style - as you will be using these later.

Margins, padding, and borders are also good properties to go over since they appear in almost every web page.

Putting it all together

  1. First, add some selectors to the HTML:
<!DOCTYPE html>
<html>
  <head>
    <title>My bumblebee website</title>
    <link rel="stylesheet" href="styles.css">
  </head>
  <body>
    <h1 id="my-header">Bees!</h1>
    <h2>Wonder, wonderful bumblebees</h2>
    <p>
      <br/>
      <img src="http://farm4.staticflickr.com/3775/12059206813_e37135c9cf_z.jpg" width="240" height="180"/>
      <br>
    </p>
    <h2>About the Bumblebee</h2>
      <h3>(From <a href="http://en.wikipedia.org/wiki/Bumblebee">Wikipedia)</a></h3>
      <p id="first-paragraph">A bumblebee is any member of the bee genus Bombus, in the family Apidae. There are over 250 known species, existing primarily in the Northern Hemisphere although they also occur in South America. They have been introduced to New Zealand and the Australian state of Tasmania.</p>
    <br>
    <h2>Types of Bees:</h2>
      <ol>
        <li class="odd">Southern plains bumblebee</li>
        <li class="even">New garden bumblebee</li>
        <li class="odd">Early bumblebee</li>
        <li class="even">Orange-belted bumblebee</li>
        <li class="odd">Buff-tailed bumblebee or large earth bumblebee</li>
      </ol>
  </body>
</html>

Now, let's update the CSS file.

/* this is a comment */

body {
  font-family: arial, helvetica, sans-serif;
  background-color: #FFFF00;
  max-width: 500px;
  text-align: center;
}

p {
  line-height: 20px;
}

h1 {
  font-style: italic;
  text-transform: uppercase;
}

#my-header {
  color: #660000;
}

#first-paragraph {
  border-bottom-style: solid;
  border-bottom-width: 2px;
  border-bottom-color: #000000;
}


.even {
 font-style: italic;
}

.odd {
  color: red;
}

Save. Refresh your browser.

What do you think? Good. Bad. Ugly? Change the color of the background and header on your end. The color picker is nice for finding colors. Update the picture, too, if you want.

Your turn!

While I provide a brief review, work along with me to develop your own basic site.

  1. Create a basic HTML page with the doctype, html, head, and body tags
  2. Add a header (H1)
  3. Create an order list
  4. Add an external CSS file (make sure to link to the HTML page)
  5. Change the background color and font size
  6. Style the list

Show it off!

Chrome Developer Tools

Using Chrome Developer Tools, we can not only view how someone added, for example, a CSS selector to make the HTML text to appear to hoover - but it's also an excellent means of testing either HTML or CSS changes directly from the browser. This can save a lot time

Open up the HTML page we worked on. Right Click on the first paragraph. Select "Inspect Element". Notice the styles on the right side of the Developer Tools pane associated with the paragraph. Do you see the styles associated with the first paragraph? Go ahead and change the size of the border from 2px to 20px:

html

Change the color of the even rows from black to something super cool.

You can also edit your HTML in real time. With Dev Tools open, right click the text and select "Edit as HTML"

Be careful as these changes are temporary. Watch what happens when you refresh the page.

Extra Credit

  1. Try some of these challenges.

More Repositories

1

awesome-fastapi

A curated list of awesome things related to FastAPI
5,592
star
2

flaskr-tdd

Flaskr: Intro to Flask, Test-Driven Development (TDD), and JavaScript
Python
2,259
star
3

awesome-flask

A curated list of awesome things related to Flask
1,143
star
4

cypress-visual-regression

Module for adding visual regression testing to Cypress
JavaScript
483
star
5

python-ruby

Should I Learn Python or Ruby?
Python
317
star
6

passport-local-express4

check out the blog post
JavaScript
290
star
7

node-stripe-charge

node + stripe + express + bootstrap 4 (used for one time charges)
JavaScript
272
star
8

microservice-movies

JavaScript
248
star
9

sublime-setup-for-python

setting up sublime text for python development
JavaScript
241
star
10

flask-redis-queue

Example of how to handle background processes with Flask, Redis Queue, and Docker
Python
207
star
11

Scrapy-Samples

Scrapy examples crawling Craigslist
Python
196
star
12

thinkful-mentor

code samples, refactoring - for thinkful students
TSQL
158
star
13

thinkful-angular

AngularJS by Example - Building a Bitcoin Investment Calculator
JavaScript
130
star
14

node-koa-api

JavaScript
130
star
15

flask-tracking

http://www.realpython.com
Python
129
star
16

typescript-node-api

TypeScript
128
star
17

node-postgres-promises

JavaScript
104
star
18

flask-basic-registration

Basic user registration package for Flask.
Python
102
star
19

passport-examples

social auth for node
JavaScript
93
star
20

node-postgres-todo

JavaScript
93
star
21

Flask-Landing

simple landing page to collect prelaunch emails
Python
64
star
22

node-swagger-api

JavaScript
63
star
23

node-mocha-chai-tutorial

JavaScript
62
star
24

whiterspace

Another minimal theme for Octopress.
JavaScript
62
star
25

angular-gulp-browserify-seed

Angular starter featuring Gulp, Bower, and Browserify
JavaScript
58
star
26

node-docker-api

developing and testing microservices with docker
JavaScript
57
star
27

twitter-sentiment-analysis

Video tutorial and accompanying output for conducting text sentiment analysis in Twitter
R
56
star
28

mean-auth

User Auth with the MEAN Stack
JavaScript
54
star
29

testing-in-django

Example project for testing in Django.
JavaScript
53
star
30

efk-kubernetes

logging in kubernetes
JavaScript
52
star
31

node-postgres-sequelize

JavaScript
52
star
32

passport-local-knex

adding passport to a node app
JavaScript
51
star
33

angular-auth-ngrx

TypeScript
50
star
34

passport-social-auth

JavaScript
49
star
35

node-docker-workflow

http://mherman.org/blog/2015/03/06/node-with-docker-continuous-integration-and-delivery
JavaScript
48
star
36

passport-local

user authentication to Node.js with Passport.js.
JavaScript
43
star
37

node-express-ajax-craigslist

scraping craigslist
JavaScript
38
star
38

web2py

Intro to web2py
Python
38
star
39

sinatra-blog

Sinatra + PostgreSQL + Heroku - on the center stage
Ruby
38
star
40

flask-stripe

Flask + Stripe + User Registration
Python
34
star
41

flask-spark-docker

Just a boilerplate for PySpark and Flask
Python
33
star
42

python-decorators

into to python decorators
Python
33
star
43

java-for-javascript

Java for JavaScript Developers
Java
30
star
44

node-twitter-sentiment

sentiment analysis with node, express, and the twitter api
JavaScript
30
star
45

mocha-chai-knex

JavaScript
29
star
46

node-token-auth

jwt auth!
JavaScript
29
star
47

angular-testing-tutorial

welcome!
JavaScript
27
star
48

flask-intro

Introduction to Flask showing much of the basic functionality. Plus, I built a task manager application called FlaskTaskr.
Python
26
star
49

node-stripe-example

JavaScript
25
star
50

react-intro

just a basic react intro
JavaScript
24
star
51

flask-rethink

a todo list with flask and rethinkdb
Python
23
star
52

django-stripe

Django + Stripe + User Registration
Python
22
star
53

express-testing-mocha-knex

testing an express app
JavaScript
21
star
54

programming-exercises

Michael Herman's stash of programming exercises
JavaScript
20
star
55

koa-passport-example

koa + passport
JavaScript
17
star
56

noLogo

minimalist octopress theme.
JavaScript
16
star
57

node-grpc-crud

JavaScript
15
star
58

python-devtest

new developer test
Python
14
star
59

vue-intro

intro to vuejs
HTML
14
star
60

flow-node-api

JavaScript
14
star
61

node-getting-started

a little more than hello world!
JavaScript
14
star
62

pinky-promise

why sign an nda when you can just pinky swear instead?
CSS
12
star
63

node-workshop

learn javascript and node!
JavaScript
12
star
64

craigslist-housing-scraper

use sparingly, at your own risk
Python
12
star
65

ancestry-scraper

Python
12
star
66

twitter-sentiment-python

basic sentiment analysis in python
11
star
67

bootstrap3

getting started with bootstrap 3
CSS
11
star
68

flask-songs-api

Python
11
star
69

octoplate

Octopress theme based on Twitter Bootstrap 3
JavaScript
10
star
70

testcafe-example

JavaScript
10
star
71

flask-ajax-form

Generate a dynamic form in Flask with AJAX
JavaScript
9
star
72

TDD-Django

Blog post and associated code repo describing TDD with Django and PyVows.
Python
9
star
73

docker-workshop

JavaScript
8
star
74

django-1.5-template

django 1.5 + custom registration + bootstrap + heroku
CSS
8
star
75

testcafe-visual-regression

JavaScript
8
star
76

running-mate

simple MLOps tool for DS/ML teams
Python
8
star
77

flask-geolocation

that's right: flask and geolocation
Python
8
star
78

django-tutorial

Code from a brief tutorial showing the basics of installing Django and setting up a simple app.
Python
8
star
79

django-tastypie-tutorial

Super Basic REST API with django-tastypie
Python
8
star
80

node-express-swig-mongo

JavaScript
8
star
81

flask-scrapy-test

for kristjan
Python
7
star
82

bottle-plotly-python

bottle.py and the plot.ly API
Smarty
7
star
83

node-bootstrap3-template

node, express, bootstrap3, boilerplate, starter, template, mongo-ready
JavaScript
7
star
84

microservice-ping-pong

JavaScript
6
star
85

bottle-user-authentication

bottle.py user login/logout/authentication bootstrap3
Python
6
star
86

django-tdd

django 1.6 test driven development!
Python
6
star
87

express-crud-pg-promise

Just a basic Node + Express CRUD app with pg-promise
JavaScript
5
star
88

hibbert-django

mike hibbert
JavaScript
5
star
89

node-oauth-openid

JavaScript
5
star
90

node-request-cheerio-scraper

scraping HN => CSV
JavaScript
5
star
91

angular4-crud

TypeScript
5
star
92

job-scraper

indeed
Python
5
star
93

generator-herman-express

generator for a basic Node/Express boilerplate
JavaScript
5
star
94

docker-rails-ecs

deliver rails app to ecs
Ruby
5
star
95

mean-token-auth

JavaScript
5
star
96

textbook

learning management system
JavaScript
5
star
97

mjhea0.github.com

code for my blog, powered by github pages and jekyll
HTML
5
star
98

ultimate-craigslist-scraper

get jobs. lots of 'em.
Python
5
star
99

indeed-scraper

stay away
Python
4
star
100

web2py-heroku

heroku + web2py
4
star