Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active February 19, 2017 13:55
Show Gist options
  • Select an option

  • Save nepsilon/850eabe8df71762d74ed33a42a4f5141 to your computer and use it in GitHub Desktop.

Select an option

Save nepsilon/850eabe8df71762d74ed33a42a4f5141 to your computer and use it in GitHub Desktop.
3 hidden HTML tips — First published in fullweb.io issue #61

3 hidden HTML tips

1. Click label to auto-focus on input:

A big plus for a good UX that all modern browsers support. Note that the pairing happens between the label’s for attribute and the input’s id attribute, not its name.

<label for="username">Fiscal Year</label>
<input type="name" name="username" id="username" />

2. Allow line breaks where it make sense:

You can control where the browser add a line break when its window is too narrow for its content. The tag to use is .

<div>Lebensabschnitt<wbr>partner</div>

Another trick is using the HTML entity &shy; to tell where to break the words. Nothing will be shown if no line break is needed, but a linking hyphen - will be shown otherwise:

<div>Lebensabschnitt&shy;partner</div> 

3. Use protocol independent URLs:

This is a best practice to avoid the ugly "This page contains both secure and non-secure content" warning. This happens when your HTTPS hosted page links to non-HTTPS resources (image, script, css, font, etc).

<script src="//domain.com/foo.js"></script>
@sykats
Copy link
Copy Markdown

sykats commented Aug 16, 2016

Very useful! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment