
After this lesson, you will be able to:
Run your my_website.py. How does it look?
Reminder: http://localhost:5000/
How do we add colors? Styles? Formatting?
We need HTML and CSS.
Pro tip: This is front-end web development!
HTML: Content, Structure, and Presentation
CSS: Style and Design

HTML means…

The fundamental building block of HTML is the element.
<p>Here is a paragraph with p tags. The tags won't appear to the user.</p>
(Most) elements consist of:
<p>).
</p>).
/.
Tags are always in angle brackets.
Different tags apply different formatting.



These are possibly the most common tags — all websites have paragraphs!

Note: As “Amazing Guitar Website” doesn’t have a p tag, it looks different. The browser doesn’t yet know how to display it.
Add <p> and </p> around the paragraphs.
See the Pen HCC - Anna Smith - List Items by Super Ternary (@SuperTernary) on CodePen.

<h1> through <h6>.<h1> defines the most important title on the page.

<p> around the paragraphs.<h1> around Anna Smith.<h2> around About Me.<h3> around Experience.There are two types of lists: - Unordered lists. - Ordered lists (aka, numbered lists).

<ul></ul> defines an unordered list.
Used together with list item: <li></li>.
<ol></ol> defines an ordered list.
List item is the same: <li></li>.
h3.We’ve talked about HTML tags.
All HTML is formed with tags:

doctypeShort for “document type declaration.”
ALWAYS the first line of your HTML.
Tells the browser we’re using HTML5 (the latest version).
Note: The CodePen did this automatically for us. It did a lot!
<html><html> is the tag for HTML content!
<html></html>.Within our <html> tags, we have:
<head></head><body></body><head><head>: The first tag inside <html></html>.
<!DOCTYPE html>
<html>
<head>
< BEHIND THE SCENES HERE! >
<title>< PAGE TITLE > </title>
<meta charset="utf-8">
</head>
<body>
</body>
</html><body><body>: The second tag inside <html></html>.
<head></head>.<!DOCTYPE html>
<html>
<head>
<title>Website Title</title>
<meta charset="utf-8">
</head>
<body>
<h1>ALL HTML CONTENT GOES HERE!</h1>
<p>Here's a paragraph with the p tag — this will actually get displayed.</p>
<h4>Put whatever you want the user to see here!</h4>
</body>
</html>html_practice.index.html.Put this content:
<!DOCTYPE html>
<html>
<head>
<title>Website Title</title>
<meta charset="utf-8">
</head>
<body>
<h1>ALL HTML CONTENT GOES HERE!</h1>
</body>
</html>Double click your file to open it in a browser!
Using the tags below, create a profile for yourself in your index.html.
Include: Name, About Me, and Hobbies.
Put all your HTML and content in between the <body> and </body> tags.
Common tags you might want to use:
<p>paragraph</p><h1>Welcome!</h1><ul>Things I like</ul>)<ol>1, 2, 3!</ol>)<li> </li>)<b>bold</b>).<!DOCTYPE html>
<html>
<head>
<title>About Me!</title>
<meta charset="utf-8">
</head>
<body>
<h1>Welcome!</h1>
<p><b>I'm Sonyl and welcome to my profile!</b></p>
<p>Things I Like:</p>
<ul>
<li>Animals</li>
<li>Food</li>
<li>Sleep</li>
</ul>
<p>My Daily Routine:</p>
<ol>
<li>Wake up</li>
<li>Drink coffee</li>
<li>Write great code!</li>
<li>Go to sleep</li>
</ol>
</body>
</html>An HTML file looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Website Title</title>
<meta charset="utf-8">
</head>
<body>
< Everything the user sees goes here. >
</body>
</html>This is the file your browser gets for any webpage you visit, like Google.com!
What about… a hyperlink that we want to click and go to another URL?

We need to tell the browser where the hyperlink should go.
<a href="Where does this link go?">Clickable text</a>
<a href="https://google.com">Click here for Google.</a>We Do: Add a link to Google in your HTML. Reload!
<img>: A picture!src.We Do: Add this image in your HTML. Reload!
Some tags need more information: Where is the link going? What is the image? Give the browser whatever it needs to know.
Don’t memorize these!
Up next: CSS!
Let’s switch gears. We have a structured website.
How do we style it?

CSS means… - Cascading Style Sheets. - Styling your HTML (e.g., colors, fonts, text sizes).
CSS tags match HTML tags.
<p>) blue.
You can set text color with color:
Color values can be specified using:
red).#FF0000).
In the CSS window, add:
CSS font size:
12px, 16px).Fun facts:

In the CSS window, add:
We can now style elements. We can style any element with a tag!
We have CSS. We need to tell the HTML about it! CodePen’s been doing this for us.
<title>, placed within <head> — it’s something for the HTML to see, but not the user.<!DOCTYPE html>
<html>
<head>
<title>Super Awesome Website</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>rel
type
href
Let’s do this.
index.html, create styles.css.In it, put:
Save and reload!
HTML structures the page; CSS styles it. The CSS tags match the HTML tags.
We put CSS in a separate file and link it to the HTML.
<!DOCTYPE html>
<html>
<head>
<title>Super Awesome Website</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<p>Here's a paragraph the user will see — it will be blue!</p>
</body>
</html>This is a crash course. It’s a huge topic! We just need the basics.
Up next: How do we do this with Flask?
Run your my_website.py — how does it look right now? Probably not the best…
Reminder: http://localhost:5000/
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello_world():
return 'Hello, World!'
if __name__ == '__main__':
app.run(debug=True)Flask automatically makes the page structure for us — the html, head, body, doctype, etc.
Discussion: Where does that “return” go? Where could we put our HTML?
Flask can have in-line styling and HTML right in the return!
return is what goes inside the body tag of the HTML.Try this:
h1.What if we have a LOT of HTML?
Copy this code over:
def hello_world():
line1 = "<h1><b>Hello</b> World!</h1>"
line2 = "<p>If music be the food of love, play on!</p>"
line3 = "<img src='https://media.giphy.com/media/sWrDT2OqxJ3Fu/giphy.gif'>"
total = line1 + line2 + line3
return totalDo you think chaining lists is sustainable for a bigger webpage?
Flask automatically makes a basic webpage for us. The HTML looks like this:
<!DOCTYPE html>
<html>
<head>
<title>Super Flask Website</title>
</head>
<body>
< What we return in Flask goes here! >
</body>
</html>Flask does that automatically — we just need to write the Python code for the body.
Up next: But what if we have a ton of code?
Create a folder called templates.
templates directory for HTML files.Create a file called index.html with some HTML:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Movie Search</title>
</head>
<body>
<p>Howdy!</p>
</body>
</html>How do we import an HTML file?
render.template.At the top of your file, add:
In the .py, change your return to return render_template("index.html").
Try it!
Now all our lines can go in the HTML:
<body>
<h1><b>Hello</b> World!</h1>
<p>If music be the food of love, play on!</p>
<img src='https://media.giphy.com/media/sWrDT2OqxJ3Fu/giphy.gif'>
</body>Try it!
Flask automatically generates the webpage HTML and puts your HTML in the body tag — whatever you put in your return statement.
If your HTML gets to be too long to put in just a function without being confusing, you can make the HTML file yourself and tell Flask to load that.
templates folder:
static folder:
Create a static folder with a file, style.css.
Your directory should look like:
project_folder
│
│ │ my_website.py
│ │
│ │
│ └───templates
│ │ └─── index.html
│ │
│ │
│ └───static
│ └───style.css
Add this to style.css:
What does it do? Reload your page!
What do you think happened?
We have:
Flask knows about:
What knows about the CSS?
What should know about the CSS? How can we do that?
CSS styles HTML docs. We know that!
As we saw earlier, the HTML doc needs to have the CSS link!
In the HTML head, we need to have:
The curly braces {{ }} call Flask!
style.css in static.”We Do: Modify your index.html’s <head>. Reload your page!
HTML structures pages. We can make a separate HTML file that Flask calls to load, in a templates folder.
CSS styles pages. We can make a separate CSS file in a static folder.
We have to tell the HTML file about the CSS file.
Flask calls the HTML file, which calls the CSS file.
Modify your HTML and CSS files. Here are some ideas:
text-align to center the content.text-decoration to underline the h1.<a href="<url>">Click here </a>?<ul><li></li></ul>?<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Movie Search</title>
<link rel="stylesheet" href="{{ url_for('static', filename='style.css')}}">
</head>
<body>
<h1><b>Hello</b> World!</h1>
<p><a href="http://www.shakespeare-online.com/plays/twn_1_1.html">If music be the food of love, play on!</a></p>
<ul>
<li>Give me excess of it, that, surfeiting,</li>
<li>The appetite may sicken, and so die.</li>
<li>That strain again! it had a dying fall:</li>
<li>O, it came o'er my ear like the sweet south,</li>
<li>That breathes upon a bank of violets,</li>
<li>Stealing and giving odour! Enough; no more:</li>
<li>'Tis not so sweet now as it was before.</li>
<li>O spirit of love! how quick and fresh art thou,</li>
<li>That, notwithstanding thy capacity</li>
<li>Receiveth as the sea, nought enters there,</li>
<li>Of what validity and pitch soe'er,</li>
<li>But falls into abatement and low price,</li>
<li>Even in a minute: so full of shapes is fancy</li>
<li>That it alone is high fantastical.</li>
</ul>
<img src='https://media.giphy.com/media/sWrDT2OqxJ3Fu/giphy.gif'>
</body>
</html>body {
background: #FEDCBA;
font-family: "Times New Roman", serif.
}
h1 {
color: #012345;
text-decoration: underline;
text-align: center;
}template and the static folders.