There isn't a direct way to manipulate the shape of a DOM element -- all elements are either rectangular (if they're display:block;
) or shaped by their text content (if they're display:inline;
).
The HTML DOM revolves around rectangular boxes, so you're not going to get random shaped boxes using that.
It depends exactly what you're trying to do. If all you want to do is draw shapes, then you'd be better off using either canvas, SVG or VML, depending on exactly what you want to do and the browser support you need.
Canvas is an HTML5 technology which basically gives you a drawing pad in the browser which you can draw on with Javascript. It allows you to create and animate 2D pixel art.
SVG and VML are vector graphic languages. They perform roughly the same task, but VML is specific to Internet Explorer while most other browsers support SVG. (IE9 will support SVG as well, but it's not in widespread use yet). Again you can work with these using Javascript, and the best way to do it in a cross-browser way is to use the Raphael libraray, which gives you an API to create your graphics, and then translates it to VML or SVG behind the scenes according to the browser.
You could also, of course, just have a background graphic for your box in the shape you want with transparent areas outside the shape, and only use the area inside the box. It won't really be a polygonal box, but if you do it right it could look just as good.
If you really want to do it using CSS - maybe to have a box that other text elements will wrap around smoothly, you're going to struggle. There are a few hacks you can use to achieve these sorts of effects, but none of them are exactly what you're looking for.
One option may be CSS transforms: This allows you to rotate/skew/etc a box. The down sides are that the box remains box-shaped (so no polygons), and the contents are rotated and skewed as well as the box outline, so may not suit what you're trying to do. Also, it may not work on all browsers, though can be made to work in most cases.
It is possible to create boxes with fake diagonal edges by messing around with the border styles. See http://www.cssplay.co.uk/menu/tree.html for a good example. But again, it's not perfect.
Other than that, you'll just have to create multiple boxes and position them to get the closest match for the shape you're trying to achieve.
Hope that helps.