CSS "example outcomes"

As part of the “examples on top” project, Kadir asked me to investigate writing some “example outcomes”, that show the effect of different values for CSS properties.

The idea here is that the “syntax examples” (i.e. the code block now at the tops of CSS pages: https://developer.mozilla.org/en-US/docs/Web/CSS/margin is good for showing you syntax, but doesn’t show you the effect of these properties. Some live samples do a very nice job of this: https://developer.mozilla.org/en-US/docs/Web/CSS/overflow-y#Result but we thought it might be worth presenting something simple and concise, further up the page.

So I’ve written a few of these in the last day or so: https://developer.mozilla.org/en-US/docs/User:wbamberg/CSS-outcomes, and you can see a couple of them in context here:
https://developer.mozilla.org/en-US/docs/User:wbamberg/Examples_on_top/position-prototype
https://developer.mozilla.org/en-US/docs/User:wbamberg/Examples_on_top/background-size-prototype

Some things I think I’ve learned from this:

  • I think they can be quite effective

  • they are more effort than JS examples but not very much more

  • I’ve used the live sample macro, to get them hosted in an iframe. One problem with that is you get the “Open with…” buttons, that aren’t really appropriate here. It would be easy to adapt the macro so you can suppress those buttons though. Alternatively, maybe there’s a better way to do this that I don’t know about.

  • this doesn’t make sense to do for all properties. For instance, I don’t see how you could build an “example outcome” for display.

  • there’s a question about how they conflict with the existing live examples. Most of the time (for example for position) I think they would complement each other quite well - the live samples are longer with more explanation and detail, the example outcomes gives a compact summary. Sometimes (for example overflow-wrap) I think the example outcome would be basically the same, only with more of the code hidden.

  • I’m still uncertain whether it’s worth doing this now if they will be made obsolete by the interactive sample editor. It will be a while until the live sample editor is fully deployed, and even when it is, these examples might still be useful in some cases.

Feedback’s welcome!

1 Like

Nice work Will - I think this all makes a lot of sense, and I support it fully.

I did have one comment — for slightly less obvious properties like display, I think we should just defer to the examples section. The whole point here is an intuitive example that doesn’t need explainer text, right? This wouldn’t work for display, as the effects are both non-obvious and can differ widely depending on the value used.

The display examples section already has a simple example that shows the same element twice, once with display: none, and one with display: block, but it could also do with links to other resources that explain the more complex uses, e.g. the guides that explain block versus inline and inline-block, flexbox, grid, etc.

Thanks Chris.

for slightly less obvious properties like display, I think we should just defer to the examples section.

Yes, I agree: it’s not appropriate for all properties, and I think it’s best to just omit it in these cases. And display is a definitely a good example of such a case.

And yes, we could do better with the display page.