Web pages are written in a combination of HTML as CSS. The basic division
is that:
HTML provides the content and structure
CSS provides the style
We don’t have time to dive deep into how to write a modern webpage, but we can look at some of the concepts.
Note
Our goal here is to learn how to write a basic webpage describing
our codes. We are not going to be able to cover web design deeply,
but hopefully we’ll learn enough so that we can use templates that
others have written to write our own pages.
HTML tags need to be opened and closed to denote a block in
which they apply. For instance: <body> opens the main
body of the page and </body> closes the main body of the
page.
Some tags are self-closing, and we end with />, for instance
in above: <metacharset="utf-8"/>
The name index.html is commonly used to indicate the first
page of a website. Many web-servers will automatically display
this page when we go to a web site.
<!DOCTYPE html><htmllang="en"><head><title>Hello</title><metacharset="utf-8"/></head><body><h1>PHY 504: Introduction to Computing in Physics and Astronomy I</h1><h2>Spring 2022</h2><p>Hello, World!</p></body></html>
CSS means cascading style sheets.
CSS files provide a set of styling rules for different HTML elements.
“Cascading” here means that the rules on a element have a hierarchy
that is followed if more than one rule tries to modify an element.
Typically we provide the styles in a separate file with the .css
extension.
For example, we can style the body of our page with a stylesheet:
A useful HTML element for grouping styles is the div tag, <div>. We can put
any content in a <div>...</div> region and specify the styling
for that region using.
HTML elements (including divs) can have either a class name or and
id selector:
<divid="name"> is used to indicate that there is a single instance
of name in the HTML page. This is called an id-selector Elements
in this div can be styled as:
#name{}
<divclass="name"> is used when we might want to have multiple
divs on the page with the same styling. This is called a class selector
and we style as:
.name{}
try it…
Let’s wrap our “Hello World” in a div and try to style it:
<pclass="center"><imgsrc="luna_bw.png"alt="picture of luna"></p>
Here, <p>...</p> denotes a paragraph
and we could style it via:
.center{text-align:center;}
Tip
Accessibility is an important design consideration when making web pages,
and you should use the alt tag to provide a text alternative to the
image for screen readers.