Centering Text

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   go to next page        

Answer:

Omitting and ending tag like </h1> makes a mess of the page.

Centering Text

Some browsers center important headings; others do not. Strictly speaking, whether a heading is centered or not is a formatting decision and should be left to the browser. The <h1> ... </h1> tags describe the function of the text they contain. However, Web authors like to have some control over the presentation of their content.

To center a heading or a paragraph (or anything else) use these tags:

<div align="center"> stuff to be centered </div>

div stands for "division". The align="center" describes what type of division you want. You can also have align="right" and align="left".

Here is a Web page. Insert some div tags to center the heading and the second paragraph. (Remember that you can use "copy", "cut", and "paste" from the edit menu of your browser with the text in the box.)

Then click to see what this HTML does. Then change it as suggested and click again.

QUESTION 10:

Try align="left" and align="right" with the second paragraph. The ending tag is </div> for all versions of the div tag.