A good first building block

Text input with a live preview

A labelled text field updates a plain-text preview without submitting data.

HTMLCSSJavaScriptNo dependencies
Edit in playground

Live preview

Explore the result below

HTML

<main><h1>A little greeting</h1><label for="name">Your display name</label><input id="name" type="text" maxlength="80" autocomplete="off" aria-describedby="hint"><p id="hint">This local demonstration sends nothing. Keep it short.</p><p id="greeting">Hello, visitor.</p><button id="clear">Clear name</button></main>
Read the complete HTML document
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">

<title>My code example</title>
<style>
:root{font-family:system-ui,sans-serif;color:#18223b}*{box-sizing:border-box}body{margin:0;min-height:100vh;padding:24px;background:#edf1ff;display:grid;place-items:center}main{width:min(100%,480px);background:white;border-radius:20px;padding:24px}h1{font-size:24px;margin:0 0 16px}button,input,select,textarea{font:inherit}button{min-height:44px;border:1px solid #afbddd;border-radius:10px;padding:10px 14px;background:#eff3ff;color:#18223b;cursor:pointer}button:focus-visible,input:focus-visible,select:focus-visible,textarea:focus-visible{outline:3px solid #3658bf;outline-offset:3px}p{line-height:1.65}label{display:block;margin:16px 0 6px}input:not([type=checkbox]),select,textarea{max-width:100%;width:100%;padding:10px;border:1px solid #afbddd;border-radius:8px}button:disabled{opacity:.5;cursor:default}
</style>
</head>
<body>
<main><h1>A little greeting</h1><label for="name">Your display name</label><input id="name" type="text" maxlength="80" autocomplete="off" aria-describedby="hint"><p id="hint">This local demonstration sends nothing. Keep it short.</p><p id="greeting">Hello, visitor.</p><button id="clear">Clear name</button></main>
<script>
const input=document.querySelector("#name"),preview=document.querySelector("#greeting");
function update(){preview.textContent="Hello, "+(input.value.trim()||"visitor")+".";}
input.addEventListener("input",update);document.querySelector("#clear").addEventListener("click",()=>{input.value="";update();input.focus();});
</script>
</body>
</html>

A little guide to making it yours

  1. Copy the code and save it in a file named example.html.
  2. Open the file in your browser to see the complete example.
  3. Change the text and structure in the HTML.
  4. Adjust the colors and spacing in the CSS, or experiment in the playground.

How it works

A real label identifies the field. The preview uses textContent, so angle brackets are displayed as text. The maxlength attribute counts UTF-16 code units. This example has no submit or storage; a production form needs its own purpose, validation and data handling.

Historical purpose: The stage-one 2014 archive recovery verified this exact detail purpose. This is an original modern implementation; no archived third-party code, credit link, remote script or guessed numeric preview mapping is reused.

Troubleshooting and limits

The greeting is assigned with textContent, so angle brackets remain literal text. Keep the input label, id and greeting target together. The value is local and is not sent or saved; a real profile form needs a backend and server validation.

This is newly authored code. It uses system fonts and no external assets.

Keep the ideas going