Settings

Theme

Small, native web tricks worth remembering

htmlcat.net

183 points by marcomezzavilla · 56 comments

Reader

19 threads
m-s-y

Love when I go into a car dealership and get to read all about the different cars. Specially when the cars aren’t actually there. In fact there’s not even a picture of a single car. Yep that’s my jam.

moontear

There are some good descriptions and hints, but what the site really needs is examples. Just looking at the code doesn't help me much. The descriptions are also mostly so short, that they could just as well be tooltips on the homepage. The whole premise of the page is a collection of "web tricks worth remembering" and I can't fathom what bash (e.g. `du -hd 1 . | sort -hr`) is doing there.

  • Aachen

    fwiw I find `*` a lot easier in regular use than all of `-d 1 .`. It doesn't automatically expand to dotfiles but for regular typing, this advice looks like something you'd do if you're a robot or making an alias

  • marcomezzavillaOP

    You’re absolutely right, thanks for the feedback. I initially included live examples (mostly through CodePen), but they were taking too much time to maintain, so I stopped.

    The Bash entry was really just a half-finished personal note that I never properly edited. It’s probably out of scope too.

    • alpinisme

      Codepen is an awful experience on mobile (and is slow, as you said). But your page is an html page about html tips. Surely you can just embed them in the page itself?

    • sam_lowry_

      Please keep it, personal notes are worth it. Maybe less navigation or +/- voting, then ranking would help us navigate your site?

      Like in the good old commandlinefu.

    • ramon156

      Silly question, why not just render the html on the pages? e.g. the popover is something I wanted to see

zeroq

Maybe it's just me, but it seems like a huge waste of time (or to be on a more positive note - potential).

Just the first example "Device type in JS".

"A coarse pointer does not mean “mobile”, and a fine pointer does not guarantee “desktop”. Ask the browser about input capabilities instead of guessing the device from its user agent."

  const input = {
  finePointer: matchMedia('(any-pointer: fine)').matches,
  coarsePointer: matchMedia('(any-pointer: coarse)').matches,
  canHover: matchMedia('(any-hover: hover)').matches,
  }; 
So it doesn't tell me how to identify device type. It doesn't even run the code so I could quickly compare results between my mobile and desktop devices to establish a baseline.
  • marcomezzavillaOP

    You’re right: it doesn’t identify the device type, so the title is misleading.

    The intended point is that device type is often the wrong thing to detect: a touchscreen laptop may expose both coarse and fine pointers, while a tablet may be connected to a mouse or trackpad. The snippet detects available input capabilities instead, which is usually what the interface should respond to.

    I wasn’t particularly careful with the titles, but this one should be "Detect input capabilities". Thanks for the heads-up!

  • wonnage

    It has all the hallmarks of just telling an agent to scrape MDN and make a website

apples_oranges

please don't hide scrollbars :)

  • chrismorgan

    Yeah, that was the first one my eyes went to. The only scenarios I can think of where it is acceptable to hide scrollbars are infinite canvases where you’ll draw your own non-linear ones (and even then be disappointed because they can’t look or behave natively), and things like maps where you remap scrolling to zoom and might want to use a backing invisible scroll area for that rather than consuming scroll events (which are somewhat more limited).

    In short: unless the native scroll bar will be wrong, do not under any circumstances hide it.

  • marcomezzavillaOP

    If you mean the "Hide scrollbars" note, I agree 100% (:

    There are a few specific situations where it can be useful, but I added the caveat precisely because it’s generally not a good practice.

    • IndySun

      >There are a few specific situations where it can be useful

      re scrollbars, Can you give an example?

      • archerx

        An online game for example.

      • marcomezzavillaOP

        Sure. I was thinking of fairly narrow cases, not ordinary page scrolling:

        - A swipe/drag carousel with visible arrows or dots, especially a looping carousel where the native scrollbar does not represent a meaningful start and end

        - An accordion or expanding panel that animates to reveal all of its content. During the transition, its intermediate height may briefly produce a scrollbar (and a visual flash), even though the fully expanded state does not need one

        - Highly visual or experimental interfaces where scrolling is communicated through another control, or where the scrollable area is decorative and scrolling is not required to access the content

  • afavour

    Only time I've seen that work is when making a carousel. Once you're using scroll snap it's already not going to behave the way you'd expect a scrollable container to, so having a different indicator doesn't feel so egregious to me.

herrherrmann

Neat! I like these opinionated lists, especially when it’s easy to browse and cherry-pick useful stuff. It’d be very good to mention how compatible the features are, though. Especially with newer CSS features, it’s easy to overestimate how ready they are for all browsers.

For that, there could just be links to the related MDN and/or caniuse.com pages.

mceachen

"... that matters" is the new emdash

tylerius

Best resource for proper HTML+CSS development is Jason Knight AKA deathshadow's CUTCODEDOWN (cutcodedown.com at Web archive) and his articles at Medium and CodePen (user Jason Knight).

OuterVale

They're not really 'tricks' as much of mentions of assorted features of HTML and CSS. You get to discover a similar assortment of things (with much more immediately available detail and many examples) just clicking around MDN.

  • happytoexplain

    Sure, they're not "tricks", but it's also definitely not the same as what you get randomly browsing formal documentation.

  • markuswagner

    What's the difference?

  • marcomezzavillaOP

    That’s fair, "tricks" may be overselling it. The website is meant to be a small, opinionated collection of features I want to remember, not a replacement for an authoritative reference like MDN. I can probably make that positioning clearer.

hk__2

> Each post-it pairs one useful platform feature with a small example

I can’t find a single example; each post-it just shows some code but not the result of it.

nater5000

I'm not sure where the design for this site came from, but I hate that it brings you to a new page to show you something that could have probably fit in the big ass buttons on the first page lol. It took my by surprise the the card didn't flip over to show you the details and instead just navigated to a new page. I'm not a design guy- more of a backend, do everything in a TUI kind of guy- so if I'm caught off guard by a cheap UI/UX decision, then that's a serious problem.

  • marcomezzavillaOP

    Agree to disagree. I don’t think preferring an in-place reveal makes navigation to a dedicated page a cheap UI/UX decision, it was a deliberate choice.

    Each note has a stable URL that can be shared or bookmarked and can be indexed independently. A dedicated page also leaves room for longer content or links to related notes.

    Flip interactions also behave differently on touch devices and require more care around keyboard accessibility. It’s a valid alternative, but I don’t see navigation to a standalone document as something inherently undesirable on the web.

  • nater5000

    Wait... there's no demonstrations of any of these "tricks" on the site? Am I looking at a broken version of the site? This could have been a markdown file lol hos is this so high up in HN?

andai

What does native mean in this context?

  • marcomezzavillaOP

    Features built directly into the browser, without requiring a framework or third-party library.

    If the term is confusing, I’m open to better wording.

mrbluecoat

I'm always googling how to center with CSS.. bookmarked.

qqrun

Thank you for sharing, it's very helpful.

zuzululu

what would be cool is an llms.txt that i can feed to use these as most try to use React when they could just use html

markuswagner

Super neat! Rare to see a genuinly actually useful opinionated list like this.

JodieBenitez

Nice tips there ! :)

vortegne

without demos this is mostly useless i think

ChrisArchitect

Not to be confused with https://http.cat/

  • stevecoalbear

    Did you know that to have a .cat domain, your content needs some link to the nation of Catalonia? That is why they offer a Catalonian translation.

  • marcomezzavillaOP

    I often end up there by accident and have a laugh every time.

robertoandred

And yet that site has horizontal scroll bars.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection