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

              
                <!-- este pen faz parte de um artigo da Alura: https://www.alura.com.br/artigos/recebendo-dados-usuario-na-web-com-inputs --> 

  <p>Teste abaixo o comportamento padrão de cada type.</p>

  <label for="lista">
  Lista com todos os types da tag input:
  </label>
  <select id="lista">
    <option disabled selected>
    Escolha um tipo de input
    </option>
    <option value="text">
    text
    </option>
    <option value="number">
    number
    </option>
    <option value="checkbox">
    checkbox
    </option>
    <option value="button">
    button
    </option>
    <option value="color">
    color
    </option>    
    <option value="date">
    date
    </option>    
    <option value="datetime-local">
    datetime-local
    </option>    
    <option value="email">
    email
    </option>
    <option value="file">
    file
    </option>
    <option value="hidden">
    hidden
    </option>
    <option value="image">
    image
    </option>
    <option value="month">
    month
    </option>
    <option value="password">
    password
    </option>
    <option value="radio">
    radio
    </option>
    <option value="range">
    range
    </option>
    <option value="reset">
    reset
    </option>
    <option value="search">
    search
    </option>
    <option value="submit">
    submit
    </option>
    <option value="tel">
    tel
    </option>
    <option value="time">
    time
    </option>
    <option value="url">
    url
    </option>
    <option value="week">
    week
    </option>
  </select>

  <div id="input-container">
  </div>  

              
            
!

CSS

              
                body {
    background-color: #ddd; 
    margin: 2rem;
    font-size: 1em;
    line-height: 1em;
    font-family: sans-serif;
    text-align: center;
}

select {
    font-size: 1rem;
}

#input-container {
  margin: 1em auto;
  border: 1px dashed #666;
  width: 300px;
  padding: 1em;
  border-radius: 10px;
}

#input-container:empty {
  border: none;
}

label {
  cursor: pointer;
}

.reset__campo datetime__campo {
  margin: 10px auto;
}
              
            
!

JS

              
                const selector = document.querySelector("select")
const inputContainer = document.querySelector("#input-container")

selector.addEventListener("change", function(e){
  
  inputContainer.innerHTML = ""
  
  const input = document.createElement("input")
  input.type = e.target.value
  
  inputContainer.appendChild(input);
  
  switch(e.target.value){
      
    case "text": 
      const labelText = document.createElement("label")
      labelText.innerHTML = "Digite texto: "
      input.placeholder = "Exemplo de texto"
      inputContainer.insertAdjacentElement('afterbegin', labelText)
      break
      
    case "number":
      const labelNumber = document.createElement("label")
      labelNumber.innerHTML = "Digite números: "
      inputContainer.insertAdjacentElement('afterbegin',labelNumber)
      break
      
    case "checkbox":
      
      inputContainer.innerHTML = ""
      
      const labelCheckbox = document.createElement("label")
      labelCheckbox.innerHTML = "Escolha uma ou mais opções: "
      inputContainer.insertAdjacentElement('afterbegin',labelCheckbox)
      
      const checkboxTemplate = `
        <div style="margin-top: 20px;">
          <label for="op1">Opção 1:</label>
          <input type="checkbox" id="op1" name="opcoes">
          <label for="op2">Opção 2:</label>
          <input type="checkbox" id="op2" name="opcoes">
          <label for="op3">Opção 3:</label>
          <input type="checkbox" id="op3" name="opcoes">
        </div>
        `
      
      inputContainer.insertAdjacentHTML('beforeend', checkboxTemplate)
      
      break
      
    case "button":
      
      inputContainer.innerHTML = ""

      const labelButton = document.createElement("label")
      labelButton.innerHTML = "Clique no botão: "
      inputContainer.insertAdjacentElement('afterbegin',labelButton)
      
      const buttonTemplate = `
        <div style="margin-top: 20px;">
          <label for="op1">Opção 1:</label>
          <input type="button" id="op1" name="opcoes1">
          <label for="op2">Opção 2:</label>
          <input type="button" id="op2" name="opcoes1">
          <label for="op3">Opção 3:</label>
          <input type="button" id="op3" name="opcoes1">
        </div>
        `
     
      inputContainer.insertAdjacentHTML('beforeend',buttonTemplate)

      break
      
    case "color":
      const labelColor = document.createElement("label")
      labelColor.innerHTML = "Escolha uma cor: "
      inputContainer.insertAdjacentElement('afterbegin',labelColor)
      break
      
    case "date":
      const labelDate = document.createElement("label")
      labelDate.innerHTML = "Defina uma data: "
      inputContainer.insertAdjacentElement('afterbegin',labelDate)
      break
      
    case "datetime-local":
      const labelDatetimeLocal = document.createElement("label")
      labelDatetimeLocal.innerHTML = "Defina uma data e hora: "
      inputContainer.insertAdjacentElement('afterbegin',labelDatetimeLocal)
      break
      
    case "email":
      const labelEmail = document.createElement("label")
      labelEmail.innerHTML = "Escreva endereço de email: "
      inputContainer.insertAdjacentElement('afterbegin',labelEmail)
      break

    case "file":
      const labelFile = document.createElement("label")
      labelFile.innerHTML = "Envie um arquivo: "
      inputContainer.insertAdjacentElement('afterbegin',labelFile)
      break
      
    case "hidden":
      const labelHidden = document.createElement("label")
      labelHidden.innerHTML = "Input hidden(seu comportamente é ficar oculto): "
      inputContainer.insertAdjacentElement('afterbegin',labelHidden)
      break

    case "image":
      const labelImage = document.createElement("label")
      labelImage.innerHTML = "Selecione uma imagem: "
      inputContainer.insertAdjacentElement('afterbegin',labelImage)
      break
      
    case "month":
      const labelMonth = document.createElement("label")
      labelMonth.innerHTML = "Escolha um mês: "
      inputContainer.insertAdjacentElement('afterbegin',labelMonth)
      break

    case "password":
      const labelPassword = document.createElement("label")
      labelPassword.innerHTML = "Digite senha: "
      inputContainer.insertAdjacentElement('afterbegin',labelPassword)
      break

    case "radio":
      
      inputContainer.innerHTML = ""
   
      const labelRadio = document.createElement("label")
      labelRadio.innerHTML = "Escolha uma opção: "
      inputContainer.insertAdjacentElement('afterbegin',labelRadio)
      
      const radioTemplate = `
       <div style="margin-top: 20px;">
         <label for="op1">Opção 1:</label>
         <input type="radio" id="op1" name="opcoes1">
         <label for="op2">Opção 2:</label>
         <input type="radio" id="op2" name="opcoes1">
         <label for="op3">Opção 3:</label>
         <input type="radio" id="op3" name="opcoes1">
       </div>
       `
       
       inputContainer.insertAdjacentHTML('beforeend',radioTemplate)
       break
       
    case "range":
      const labelRange = document.createElement("label")
      labelRange.innerHTML = "Escolha um ponto no nível: "
      inputContainer.insertAdjacentElement('afterbegin',labelRange)
      break

    case "reset":
      
      inputContainer.innerHTML = ""

      const labelReset = document.createElement("label")
      labelReset.innerHTML = "Redefinir: "
      inputContainer.insertAdjacentElement('afterbegin',labelReset)
      
      const resetTemplate = `
       <form>
         <fieldset>

           <div class="reset reset__campo">
           <label for="pais"><strong>País:</strong></label>
           <input type="text" name="pais" id="pais" placeholder="Preencha aqui">
           </div>

           <div class="reset reset__campo">
           <label for="estado"><strong>Estado:</strong></label>
           <input type="text" name="estado" id="estado" placeholder="Preencha aqui">
           </div>

            <div class="reset reset__campo">
            <label for="cidade"><strong>Cidade:</strong></label>
            <input type="text" name="cidade" id="cidade"  placeholder="Preencha aqui">
            </div>
            <input type="reset">
          </fieldset>
        </form>
        `
       inputContainer.insertAdjacentHTML('beforeend',resetTemplate)
       break
      

     case "search":
       const labelSearch = document.createElement("label")
       labelSearch.innerHTML = "Pesquisar: "
       inputContainer.insertAdjacentElement('afterbegin',labelSearch)
       break

     case "submit":
       const labelSubmit = document.createElement("label")
       labelSubmit.innerHTML = "Clique para enviar: "
       inputContainer.insertAdjacentElement('afterbegin',labelSubmit)
       break
      
     case "tel":
       const labelTel = document.createElement("label")
       labelTel.innerHTML = "Digite número de telefone: "
       inputContainer.insertAdjacentElement('afterbegin',labelTel)
       break
    
     case "time":
       const labelTime = document.createElement("label")
       labelTime.innerHTML = "Defina um horário: "
       inputContainer.insertAdjacentElement('afterbegin',labelTime)
       break

     case "url":
       const labelUrl = document.createElement("label")
       labelUrl.innerHTML = "Inserir link: "
       inputContainer.insertAdjacentElement('afterbegin',labelUrl)
       break

     case "week":
       const labelWeek = document.createElement("label") 
       labelWeek.innerHTML = "Defina semana do ano: "
       inputContainer.insertAdjacentElement('afterbegin',labelWeek)
       break
     
     default:
  }
    
})

              
            
!
999px

Console