Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

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

              
                <form>
  <div class="form-group">
    <label for="username">ユーザー名:</label>
    <input type="text" id="username" name="username" required placeholder="ユーザー名を入力してください">
    <span class="error-message">ユーザー名は必須です。</span>
  </div>

  <div class="form-group">
    <label for="email">メールアドレス:</label>
    <input type="email" id="email" name="email" required placeholder="有効なメールアドレスを入力してください">
    <span class="error-message">有効なメールアドレス形式で入力してください。</span>
  </div>

  <button type="submit">送信</button>
</form>
              
            
!

CSS

              
                /* --- 基本的なフォーム要素のスタイル --- */
body {
  font-family: sans-serif;
  background-color: #f7f7f7;
  padding: 20px;
}

.form-group {
  margin-bottom: 20px;
  padding: 15px;
  border: 1px solid #ddd; /* 通常時の枠線 */
  border-radius: 8px;
  background-color: #ffffff; /* 通常時の背景色 */
  transition: all 0.3s ease; /* スムーズな変化のためにトランジションを追加 */
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-weight: bold;
  color: #333;
}

.form-group input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid #ccc; /* 通常時の入力欄の枠線 */
  border-radius: 5px;
  box-sizing: border-box;
  font-size: 16px;
  transition: border-color 0.3s ease;
}

/* エラーメッセージの初期設定(デフォルトでは非表示) */
.error-message {
  color: #e74c3c; /* エラーメッセージの色 */
  font-size: 0.85em;
  margin-top: 8px;
  display: none; /* ここが重要:初期状態では非表示 */
}

.form-group:has(input:user-invalid) {
  border-color: #e74c3c; /* 無効な入力がある場合の親の枠線を赤くする */
  background-color: #fff0f0; /* 無効な入力がある場合の親の背景を薄い赤にする */
}

/* 無効な入力欄がある場合の入力欄自体のスタイル */
.form-group:has(input:user-invalid) input {
  border-color: #e74c3c; /* 入力欄自体の枠線も赤くする */
}

/* 無効な入力がある場合に、その中のエラーメッセージを表示 */
.form-group:has(input:user-invalid) .error-message {
  display: block; /* エラーメッセージを表示 */
}


              
            
!

JS

              
                
              
            
!
999px

Console