HTML basics and Hello World! Your first step
Before creating an experiment with jsPsych, learn how an HTML page is organized and how to write its basic parts. In this lesson, you will open a small example, read it from top to bottom, and make a change of your own.
What is HTML?
HTML stands for HyperText Markup Language. It describes the structure and meaning of a web page. For example, HTML tells the browser which text is a heading, which text is a paragraph, and where an image belongs. HTML is not a programming language for calculations; it is a markup language that organizes page content.
HTML uses words in angle brackets, such as <p>, called tags. Most elements have an opening tag and a closing tag. The closing tag has a slash before the tag name.
<p> Hello World! </p>
<p> is the opening tag. Hello World! is the content. </p> is the closing tag.
The opening tag, content, and closing tag together make one paragraph element: <p>Hello World!</p>.
Your first HTML page
Open the shared sample in a new tab. The same sample file is used by the Japanese and English lessons. It is stored directly in the jspsych folder, beside dist and media; do not move it into en.
View the sample code
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Hello World! | はじめてのHTML</title>
</head>
<body>
<h1>はじめてのHTML / My first HTML page</h1>
<p>Hello World!</p>
</body>
</html>
Read the code from top to bottom
-
<!DOCTYPE html>This declaration tells the browser to interpret the document using modern HTML. It is not an HTML tag. Put it at the very beginning of the file.
-
<html lang="ja"> ... </html>The
htmlelement wraps the entire page. Thelangattribute tells browsers and assistive technologies which language the page mainly uses. This shared sample uses Japanese for its main language; English text can still appear in the page. -
<head> ... </head>The
headelement contains information and settings about the page. Most of its contents are not shown in the page itself. -
<meta charset="UTF-8">This sets the character encoding to UTF-8. UTF-8 supports many languages and helps prevent text, including Japanese, from appearing as garbled characters. This
metaelement has no separate closing tag. -
<meta name="viewport" content="width=device-width, initial-scale=1.0">This setting helps the page use the actual screen width on a phone or tablet. Without it, a mobile browser may display the page as if it were much wider and shrink it to fit.
-
<title>...</title>The title is shown in the browser tab and may be used in bookmarks or search results. It is different from the heading displayed inside the page.
-
<body> ... </body>The body contains the page content that visitors see. In this example, it contains one heading and one paragraph.
-
<h1>...</h1>and<p>...</p>h1marks the main heading of this page.pmeans paragraph and marks a block of text. The text between each pair of tags is the content displayed by the browser. -
</body>and</html>Close the elements in the reverse order in which they were opened. The body closes first, then the outer html element closes last.
Basic rules for writing HTML
These habits make HTML easier to read and help prevent small mistakes. You will use the same habits when you start editing jsPsych examples.
- Close elements that have an opening and closing tag. Write
<p>Text</p>. The slash in</p>marks the closing tag. Some elements, such as<meta>, do not have a closing tag. - Close nested elements in the right order. If one element is inside another, close the inner element first:
<body><p>Text</p></body>. Do not close the body before closing its paragraph. - Indent nested lines. Move the contents of
headandbodyinward by one level (often four spaces or one Tab). Indentation usually does not change what the browser displays, but it makes the parent-child structure much easier to see. - Write attributes inside the opening tag. An attribute adds information to an element. For example,
lang="ja"is an attribute on the openinghtmltag. Keep the value inside quotation marks. - Use lowercase tag names consistently. Browsers may accept uppercase letters, but lowercase names such as
<body>are conventional and easier to compare with examples. - Save the file with an
.htmlextension. Use a simple name such ashello-world.html. Keeping the sample beside thedistfolder also ensures that its relative file paths keep working. - Keep the content and its tags paired. Text that should appear on the page belongs between the opening and closing tags, not before or after them.