Stack Snippets are an on-site tool similar to http://jsfiddle.net or http://codepen.io or http://plnkr.co. They're more limited than those tools, but they have the advantage of being on-site, so your code / markup is in your question (or answer), not just linked, and so it's accessible even if the off-site location isn't, and people don't have to go off-site to help you / get help from you. They were announced and initially documented in this SE blog post, but it's markedly out of date now.
Grade: Snippets are for runnable examples in the browser demonstrating a problem. If your snippet code isn't going to be runnable in the browser (see Steps 3 and 4 below), don't use a snippet; just highlight it and use the button (or) - or indent each line four spaces - to format your code as a code block instead.
This answer covers snippets generically. Some libraries or technologies have their own answers tailored specifically to them:
To create a snippet:
Open the Stack Snippets editor, either by clicking the toolbar button or, with the cursor present in the answer box, pressing:
That will give you a pop-up dialog with controls on the left and four panes on the right:
If your code needs Ajax, you can simulate it with and static data.
If you need to show that isn't preventing the default of following a link, see this question about how to do that (since Stack Snippets won't let you navigate to a different document or open a new window). (TL; DR - Use a link to a fragment identifier.)
Make sure your code is properly and consistently formatted. (You can use the Tidy button in the editor to have it apply its rules to your code if you like.)
When the snippet works, demonstrating what you're trying to show, and the code is properly and consistently formatted, click Save & insert into post to save it to the text of your question (or answer) and close the snippet editor. (You can always reopen it later by clicking the edit the above snippet link under the snippet.)
The four panes in the snippet editor are:
HTML - The top-left pane. Only the content goes here. When you run the snippet, it will be wrapped in markup including tags.
CSS - The top-right pane. Your CSS goes here, as though it were in a stylesheet or an element (which is where it will go).
Result - The bottom-right pane. Your snippet is rendered here.
To run the snippet, click run
To pass the code and markup through a "pretty printer", click Tidy
To completely wipe out the code and settings in the snippet editor, click Reset
To leave the editor without saving the snippet to your post, click Cancel
Including libraries, etc.
If the library you want to use is listed in the drop-downs on the left, just pick it from the drop-down; the editor will insert a tag (or multiple tags) in the HTML for that library. You can always edit or remove it later.
To include a library or stylesheet that isn't listed, you can use the Add an external library button and provide a URL; the editor will then automatically add either a tag or a tag for it in the HTML pane. Typically you'd source these from a CDN like http://cdnjs.com.
If your code needs Ajax, you can simulate it with and static data. Instead of:
or if you need a promise:
By default, an in-snippet console will be included, so that and similar statements generate output to the result pane. This involves adding console-specific CSS and markup to your snippet, which in some relatively-rare cases may interfere with what you're trying to show. If you don't intend to use and such, untick the box. If you do, though, it's very handy to have those results shown in the result pane rather than hidden away in the browser's console.
The console is limited to only the bottom of the result window. If your only output is to the console, you can force that area to fill the window by adding this CSS (sadly, there is no actual option for doing this):
... or of course use your own limit by supplying a number other than 50.
canon, who wrote the snippet console, added some other options years ago, but they don't appear to have been deployed to the SE network, and no UI for the options exists.
By default, your code is run "as is" in the browser. But if you tick the Use BabelJS / ES2015 checkbox, your code will be transpiled using the in-browser version of http://babeljs.io. This isn't needed much here in 2017 as all major browsers support the vast majority of ES2015 +, but you'd use it for a React snippet for example.
Showing / hiding by default
By default, when you insert your snippet in your post, it will show the content of the snippet. Often that's exactly what you want: to show your code. But if you're doing a snippet that's just a live example of code blocks you've already written, or demonstrating minor tweaks to a previous snippet, etc., you may not want it to take up that much space. If so, tick the Hide snippet by default checkbox.
- We don't have a tag around our CSS
- In this case, we didn't tick the Hide snippet by default checkbox, so the snippet's code is shown
- Since we weren't using the console, we unticked the Show console checkbox
Here's that exact same snippet, but with the Hide snippet by default checkbox ticked:
- How to reset instances poe
- How do I build a Merta-Attentaeter armor
- Who married dani behr
- How to simulate mouse movements and click
- Silenciar Conversacion WhatsApp Plus
- What is solar kernel oil
- 7 dtd where to find potassium
- Skyrim where the melt is in Riften
- How to post coordinates in the war commander
- How to save a game on 3ds
- Logitech everywhere mx repair manuals
- What does age-appropriate
- What happened to Anthony Ragdoll Scalamere
- How to make ku band antenna
- Who killed Mazaradi fox Jimmy's henchman
- Dolphin fish how to catch a scam
- Vjti mumbai placemats wholesale
- Dipalmitoylethylhydroxyethylmoniummethosulfat wikihow
- Dan Howell handwriting font
- How do you cut seeds
- Christopher james dannevig wikihow
- What are bond index funds
- Engine hour counter how it works
- How to adjust Pedder's extreme coilovers