Saltar al contenido
MINESWEEPER

How to Embed Minesweeper in a Moodle Course

Moodle strips iframes from most of what users type, but it deliberately leaves Page resources alone, so that is where the game goes. Paste the snippet through the editor's Source code view and the board is live. If your administrator cleans content everywhere, a URL resource with Display set to Embed does the same job without any HTML.

Time needed
About 3 minutes
Resource
Page
Editor view
Tools > Source code
Fallback
URL, Display: Embed
<iframe
  src="https://play-minesweeper.games/embed/?size=beginner&noguess=1"
  width="344"
  height="472"
  frameborder="0"
  style="border:0;max-width:100%"
  loading="lazy"
  title="Minesweeper Game"
  allow="clipboard-write"
></iframe>
<p style="font:12px/1.5 Tahoma,'MS Sans Serif',Geneva,sans-serif;color:#555555;margin:6px 0 0;max-width:344px">
  <a href="https://play-minesweeper.games/" style="color:#555555">play-minesweeper.games</a> — free Minesweeper, no download
</p>

A Beginner 9×9 board in no-guess mode (noguess=1), 344 × 472 pixels: every board can be solved by logic, and the frame fits the content area of the Boost theme and the Moodle app.

For the URL resource route you only need the address: https://play-minesweeper.games/embed/?size=beginner&noguess=1. The paragraph after the iframe is the credit link that keeps the embed free; with a URL resource, put that link in the resource's description instead.

Adding the game as a Page resource

  1. Turn on Edit mode in your course

    Open the course and switch on the Edit mode toggle at the top right. You need a role that can add activities, which the standard Teacher role can.

  2. Add a Page resource

    In the section where the game should go, click Add content and choose Activity or resource (on Moodle 4.4 and earlier, click Add an activity or resource). Pick Page from the activity chooser and give it a name such as "Logic warm-up: Minesweeper".

  3. Open the source code view of Page content

    Scroll to Page content. In the TinyMCE editor, open the Tools menu (or the View menu) and choose Source code. On older sites still running the Atto editor, click Show more buttons first, then the HTML button. Paste the snippet into the code window and click Save in that window.

  4. Save and display

    Back in the visual editor the board shows as a placeholder or live frame. Scroll down and click Save and display. Moodle opens the finished page, and you should be able to play a round straight away.

  5. If the board is missing, use a URL resource instead

    If the saved page shows no game at all, your site cleans HTML everywhere. Delete the Page, add a URL resource instead, put the game address in External URL, and under Appearance set Display to Embed. Moodle then builds the frame itself, so there is no HTML for it to remove.

Why the iframe survives in a Page and not in a forum

Moodle protects every course from harmful code by cleaning the HTML that users save. The cleaner, HTML Purifier, removes iframes outright. What matters is which text Moodle cleans:

  • Not cleaned: Page content, Text and media areas, and the descriptions of activities and resources. Moodle leaves these alone on purpose so that teachers can add media, scripts and inline frames. Your iframe stays exactly as pasted.
  • Cleaned: anything students can write in — forum posts, assignment submissions, wiki pages, glossary and database entries, blogs. The editor shows the iframe while you type, then it disappears on save.
  • Cleaned unless trusted: activities that support trusted text, such as forum posts and glossary entries. If an administrator enables Enable trusted content (Site administration > Security > Site security settings), text from roles with the moodle/site:trustcontent capability — Teacher and Manager by default — is marked trusted and skips cleaning.

Two administrator settings change the picture. Content cleaning everywhere (Site administration > Development > Experimental settings) cleans Pages and descriptions too, and then the iframe disappears from every editor field; the URL resource is the way round it. Allow EMBED and OBJECT tags, on the Site security settings page, is often suggested as a fix but only covers those two older tags and has no effect on iframes.

Not an admin? You rarely need one: a Page works on a default Moodle site. If it does not, ask your Moodle administrator whether Content cleaning everywhere is on, or use the URL resource route below.

The URL resource route

A URL resource needs no HTML at all, so nothing can strip it. With Edit mode on:

  1. Click Add content > Activity or resource and choose URL.
  2. Enter a name and paste https://play-minesweeper.games/embed/?size=beginner&noguess=1 into External URL, including the https://.
  3. Under Appearance, set Display to Embed.
  4. Add the credit line to the description: "Minesweeper by play-minesweeper.games", linked to the site.
  5. Click Save and display.

Moodle draws the frame and sizes it to fill the page, so the board shows with space around it. If Embed is not in the Display list, the administrator has limited the Available display options for URL resources; Open loads the game in the same window instead, and In pop-up opens a separate window.

Troubleshooting

  • The page shows nothing where the game should be. Open Edit settings and look at Page content in Source code. If the iframe is gone, the site cleans content everywhere; switch to the URL resource. If it is there, the frame is being blocked.
  • The frame is there but empty or shows a block message. The school web filter blocks the domain. Open the game address in a normal tab on the school network to confirm, and see our notes on playing Minesweeper at school.
  • The bottom row is cut off. The height was changed or the snippet was trimmed. Restore height="472" in Source code; the board needs the full height for its header and status line.
  • The game shows as code text. It was pasted into the visual editor, not the Source code window. Delete it and paste again through Tools > Source code.
  • The game vanished after a course restore on another site. Backups keep Page content, but a site with Content cleaning everywhere switched on cleans it when the page is displayed. Re-add the game as a URL resource there.

Using it in class

The Minesweeper lesson for teachers is a 15-minute logic activity designed around this board. In Moodle, put the board on a Page with the rules students should discover underneath, and follow it with a forum where they explain one deduction in their own words. For paper practice or homework, link the printable Minesweeper worksheets; every sheet comes with an answer key.

Moodle embed questions

Why did Moodle remove my iframe?

Moodle runs most text through HTML Purifier, which deletes every iframe. Page content and activity descriptions are exempt so that teachers can add media and inline frames, unless your administrator has turned on Content cleaning everywhere. In forum posts, assignment submissions, wikis, glossaries and other places students write, iframes are removed on save. Use a Page, a Text and media area or a URL resource set to Embed.

Will "Allow EMBED and OBJECT tags" fix a stripped iframe?

No. That setting only allows the older embed and object tags; it does not affect iframes, and this snippet uses neither tag. What decides whether an iframe survives is where you paste it (a Page keeps it) and, in forum-style activities, whether Trusted content is enabled and your role has the moodle/site:trustcontent capability.

Can I put the game directly on the course page?

Yes. Add a Text and media area (called Label before Moodle 4.1) instead of a Page and paste the snippet through Source code in the same way. Its text is not cleaned either. Keep to the Beginner board there: the course page column is narrow, and a larger board would be squeezed into a frame that scrolls.

What does the URL resource with Display: Embed look like?

Moodle opens a page with the course header and a frame underneath that fills the available space, with your game inside it. Use https://play-minesweeper.games/embed/?size=beginner&noguess=1 as the External URL. If Embed is missing from the Display list, your administrator has removed it from the URL resource’s Available display options; choose Open or In pop-up instead.

Does it work in the Moodle app?

A Page with the iframe displays in the Moodle app, and the snippet narrows to the screen thanks to max-width:100%. Players place flags with a long press. If your site uses the URL resource route, the app may open the address in the browser instead.

Do students need an account or plugin?

No. There is nothing to install in Moodle and no account on the game site. The board runs in the frame, has no ads, and no-guess wins are never submitted to the public leaderboard.

Everything on this page starts with a snippet from the generator: a game frame plus a one-line credit link that goes under it. Pick a board size and theme, decide whether to show the optional "Powered by" line inside the game, then copy the code.

Open the Minesweeper embed generator

Also useful: the Minesweeper widget generator and iframe options, how to play Minesweeper, and custom board sizes.