Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

JavaScript

Babel is required to process package imports. If you need a different preprocessor remove all packages first.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <html>
  <head>
    <meta charset="utf-8">
    <title>HTML5で作る各種フォーム</title>
    <link rel="stylesheet" href="style.css">
  </head>
  <body>
    <form id="myForm" method="get">

      <label>半角英数文字のみ有効:
        <input name="userid" pattern="^[0-9A-Za-z]+$" title="半角英数文字のみ有効" value="userid" required>
      </label>
      <label>検索:
        <input type="search" name="q" list="keywords">
        <datalist id="keywords">
        <option value="プログラミング">
        <option value="ロボット">
        <option value="Webデザイン">
        </datalist>
      </label>
      <label>メールアドレス:
        <input type="email" name="emailN" autocomplete="email" placeholder="ex) addr@sample.co.jp" required>
      </label>
      <label>パスワード:
        <input type="password" name="passN" required>
      </label>
      <label>URL:
        <input type="url" name="urlN" required>
      </label>
      <label>数値:
        <input type="number" name="numberN" min="5" max="10" required>
      </label>
      <label>カラーピッカー:
        <input type="color" name="colorN" required>
      </label>
      <label>時間:
        <input type="time" name="timeN" required>
      </label>
      <label>日付:
        <input type="date" name="dateN" required>
      </label>
      <label>レンジ:
        <input type="range" name="rangeN" max="50" min="0" step="2">
      </label>
      チェックボックス:
      <label><input type="checkbox" name="chk1" value="tokyo">東京</label>
      <label><input type="checkbox" name="chk2" value="osaka">大阪</label>
      <label><input type="checkbox" name="chk3" value="fukuoka">福岡</label>
      ラジオボタン:
      <label><input type="radio" name="radioN" value="join" checked>参加</label>
      <label><input type="radio" name="radioN" value="abstention">不参加</label>
      <button id="button" type="submit">送信</button>
    </form>
    <hr />
    <p>フォームの送信値は次の通りです。</p>
    <ul class="result">
    </ul>
    <table border="1">
      <tr>
        <th>Type</th><th>Name</th><th>Value</th>
      </tr>
      <tbody id="list">
      </tbody>
    </table>
  </body>
</html>
              
            
!

CSS

              
                body {
  margin: 0;
  padding: 5px;
  font-size: 16px;
}

label {
  display: block;
  margin-bottom: 5px;
  margin-right: 5px;
}

input {
  font-size: 16px;
}

/* 正常の場合のスタイル */
input:valid {
  border: 2px solid #dddddd;
  background: #ffffff;
}

/* エラー場合のスタイル */
input:invalid {
  border: 2px solid #be2a2a;
  background: #ffcbdd;
}

button {
  font-size: 16px;
}
              
            
!

JS

              
                var myForm = document.getElementById('myForm');
myForm.addEventListener('submit', function(event) {
  event.preventDefault();

  var list = document.getElementById('list');
  while (list.firstChild) list.removeChild(list.firstChild);

  var elements = document.getElementsByTagName("input");
  for(var i=0; i<elements.length; i++){
    var type = elements[i].type;
    var name = elements[i].name;
    var key = elements[i].id;
    var checked = elements[i].checked;
    var value = elements[i].value;
    if(type == "checkbox" || type == "radio"){
      if (checked) {
        view(name, type, value, list);
      }
    }else {
      view(name, type, value, list);
    }
  }

}, false);

// 画面に表を作成する関数
var view = function(name, key, value, list) {
  var tr = document.createElement('tr');
  var td1 = document.createElement('td');
  var td2 = document.createElement('td');
  var td3 = document.createElement('td');
  list.appendChild(tr);
  tr.appendChild(td1);
  tr.appendChild(td2);
  tr.appendChild(td3);
  td1.innerText = key;
  td2.innerText = name;
  td3.innerText = value;
}
              
            
!
999px

Console